Resolved:cURL and HTTP File Upload
Posted: Tue Apr 28, 2009 5:29 am
Good Day
I am trying to upload a file from my local server to a remote Linux server. I managed to put this together after browsing the forum:
However I am getting the following message:
301 Moved Permanently
I am a bit lost as to why it doesn't upload the file and it returns this message. Any help would be appreciated.
EDIT: If I put a / in the url like this
Still don't know what is causing the error? Perhaps a web server setting? Using Apache/2.0.54
I am trying to upload a file from my local server to a remote Linux server. I managed to put this together after browsing the forum:
Code: Select all
$url = "http://mydomain/curl";
$localfile = "test.txt";
$fp = fopen ($localfile, "r");
$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_USERPWD, 'username:password');
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);
curl_close($ch);
fclose($fp);
print $http_code;
print "<br /><br />$http_result";
if ($error)
{
print "<br /><br />$error";
} // if ($error)301 Moved Permanently
I am a bit lost as to why it doesn't upload the file and it returns this message. Any help would be appreciated.
EDIT: If I put a / in the url like this
It then returns this message: 405 Method Not Allowed
Still don't know what is causing the error? Perhaps a web server setting? Using Apache/2.0.54