File upload does not work with cURL
Posted: Fri Aug 25, 2006 11:39 am
I am trying to upload a file using cURL.
but it did not seem to work. it calls the target file but does not send the file contents I suppose.
I have now included the file upload cURL script, file handler script, file to be uploaded and resultant string
of the operation.
cURL script: fileupload.php[EDITED]
target file: tempUpload.php
file to be uploaded: uploadthisfile.txt
output:
but it did not seem to work. it calls the target file but does not send the file contents I suppose.
I have now included the file upload cURL script, file handler script, file to be uploaded and resultant string
of the operation.
cURL script: fileupload.php[EDITED]
Code: Select all
<?php
echo "\n current working directory of php: ".shell_exec('pwd');
$url = "http://suse/test/tempUpload.php";
$ch = curl_init(); // initialize curl handle
$fileToUpload = "uploadthisfile.txt";
$fp = fopen( $fileToUpload, "r+");
echo "\n contents of file to be uploaded: ".file_get_contents( "uploadthisfile.txt" );
curl_setopt($ch, CURLOPT_URL,$url); // set url to post to
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_INFILE, $fp );
curl_setopt($ch, CURLOPT_INFILESIZE, filesize( $fileToUpload ));
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, "submit=upload&MAX_FILE_SIZE=40000000" );
curl_setopt($ch, CURLOPT_UPLOAD, 1);
$return = curl_exec( $ch );
echo "\n error: ".curl_error( $ch );
echo "\n return from target file: ".$return;
curl_close( $ch );
?>Code: Select all
<?php
echo "i will upload your file";
print_R( $_FILES );
print_r( $_POST );
?>Code: Select all
hellooutput:
Code: Select all
Suse:/opt/lampp/bin # ./php phpdocs/fileupload.php
current working directory of php: /opt/lampp/bin
contents of file to be uploaded: hello
error:
return from target file: i will upload your fileArray
(
)