Curl PUT problem

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I recently moved my website to a new server and everything is working
just fine except this small PHP script that puts a XML file onto my
main website. This script worked on the old server does not work on
the new one.

$url = " ";
$localfile = "/var/www/CEBrates.xml";
$fp = fopen ($localfile, "r");
$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_USERPWD, 'myname:mypassword');
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PUT, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));
$http_result = curl_exec($ch);
$error = curl_error($ch);
$http_code = curl_getinfo($ch ,CURLINFO_HTTP_CODE);
if ($error) {
   print "$error";

I am not getting any errors but the resulting XML file on the main
website is 0 bytes, However if I manually upload the XML file with FTP
the file size is 2kB.


Re: Curl PUT problem

Quoted text here. Click to load it

You might, if you checked for them.

You assume that fopen() succeeded, but you don't check.
You assume that curl_init() succeeded, but you don't check. (What if curl
isn't installed?)
You assume that curl_exec() succeeded, but you don't check.
You retrieve a value from curl_error() but execute several more statements
before you check it.

Lastly, since this is now on a different server: is error reporting even
turned on, on the new server?

Bottom line: this is *not* a robust script. It is written to assume that all
operations are successful, and it isn't capable of detecting terribly many of
the problems that might occur.

Site Timeline