After several hours of research, I could not solve the problem with PHP and cURL.
When I try to send the file directly from the form, the curl works fine.
<form method="post" action="" enctype="multipart/form-data"> <input name="file" type="file" /> <br /> <input name="submit" type="submit" value="Upload" /> </form> <?php $temp = $_FILES['file']['tmp_name']; $name = $_FILES['file']['name']; $post = array ( 'file' => '@'. $temp ); $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt ($ch, CURLOPT_POST, true); curl_setopt ($ch, CURLOPT_POSTFIELDS, $post); $exec = curl_exec ($ch); curl_close ($ch); ?>
The above code is working correctly. When I try to use your form, the file is sent correctly.
My problem is that I need to send files that are already on the server.
I tried with the full path to go to the file "C: /xampp/htdocs/test/photos.zip", but for some reason does not work.
$post = array ( 'file' => '@C:/xampp/htdocs/test/photos.zip' );
Does anyone know how I'm doing to send files already sent to the server?
Edit:
upload.php (server)
<?php error_reporting( E_ALL ); $upload = $_FILES['file']; move_uploaded_file( $upload['tmp_name'], 'photos.zip'); ?>
myuploadtest.php (localhost)
<form action="" method="post" enctype="multipart/form-data"> <input name="file" type="file" /><br /> <input name="submit" type="submit" value="Upload" /> </form> <?php $temp = $_FILES['file']['tmp_name']; $name = $_FILES['file']['name']; $post = array( 'file' => '@'.$temp ); $url = "http://www.mysite.com/upload.php"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); $exec = curl_exec($ch); curl_close($ch); ?>
uploadcurl.php (localhost)
<?php $post = array( 'file' => '@C:/xampp/htdocs/test/photos.zip' ); $url = "http://www.mysite.com/upload.php"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); $exec = curl_exec($ch); curl_close($ch); ?>
Thanks in advance.