I am currently working on a project with php. Here I want to store the image into folder using move_uploaded_file
but when I use the following code :
Hello
I know the ticket was open a while ago but i have been looking for this complete code for a while and I only found pieces of it on the net but nothing that fully worked, so here it is. I hope it helps some people.
I saw your post and i had exactly the same issue using most of the information found here - main author of the code below with w3schools.
Here is how it can be done, two ways :
// the index.php file on the server
Formulaire de téléchargement d'une image
the upload.php file, in the same dir in this case
";
echo $uploadfile;
echo "
";
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $uploadfile)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
Server that sends the file (your web server) : send.php
'123456','file_contents'=>'@'.$file_name_with_full_path);
$post = array('file_contents' => new CurlFile($file_name_with_full_path, 'text/plain' /* MIME-Type */,'' /*directory*/));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$result=curl_exec ($ch);
curl_close ($ch);
echo $result;
?>
and the file on the receiving server end : receive.php
";
print_r ($uploadfile);
echo "
";
echo '';
if (move_uploaded_file($_FILES['file_contents']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Possible file upload attack!\n";
}
echo 'Here is some more debugging info:';
print_r($_FILES);
echo "\n
\n";
print_r($_POST);
print "\n";
?>
Sources and references to other codes :
http://stackoverflow.com/questions/12667797/using-curl-to-upload-post-data-with-files
http://stackoverflow.com/questions/15200632/how-to-upload-file-using-curl-with-php
http://code.stephenmorley.org/php/sending-files-using-curl/
http://www.w3schools.com/php/php_file_upload.asp
Thanks again to the true authors of 99% of the code, fixed with peoples comment on stackoverflow forum : derakkilgo and W3SCHOOLS.