curl-users
Problems using PHP CURL option CURLOPT_READFUNCTION
Date: Fri, 1 Aug 2003 01:55:24 +0300
Hi!
I use Curl (libcurl 7.9.8 /OpenSSL 0.9.6g ) in PHP (Version 4.3.0 ) on Windows 2000 Server platform (IIS web server). Everything is working as expected.
I would like to transfer a file to ftp site using Curl.
As stated in the PHP Curl FAQ:
****************************
5.5 Does CURLOPT_FILE and CURLOPT_INFILE work on win32 ?
Yes, but you cannot open a FILE * and pass the pointer to a DLL and have
that DLL use the FILE *. If you set CURLOPT_FILE you must also use
CURLOPT_WRITEFUNCTION as well to set a function that writes the file, even
if that simply writes the data to the specified FILE*. Similarly, if you use
CURLOPT_INFILE you must also specify CURLOPT_READFUNCTION.
****************************
I have no idea how the function specified in CURLOPT_READFUNCTION option should look like !?!
My code is:
************************
<html><head><title>whatever</title></head>
<body>
<?php
// Here I should put file data that should be sent to FTP server ?!?
function read_body($ch, $string) {
$len = strlen($string);
return $len;
}
$post="POST";
$url = "ftp://user:password@ftpserver.com:21/pub/test1.txt";
$filename = "D:\\test1.txt";
if (!$handle = fopen($filename, 'r')) {
print "Cannot open file ($filename)";
exit;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_VERBOSE, 1 );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_READFUNCTION, "read_body" );
curl_setopt($ch, CURLOPT_FTPASCII, 1);
curl_setopt($ch, CURLOPT_INFILE, $handle );
curl_setopt($ch, CURLOPT_INFILESIZE, filesize( $filename ) );
curl_exec($ch);
curl_close($ch);
fclose ($handle);
?>
</body></html>
************************
If I execute it, after a few minutes I receive a Timeout error message on screen without any data :(
Please help me write this TXT file to FTP server using CURL in PHP on Windows.
Best regards
Stefan
-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
Received on 2003-08-01