I've sent some post data with cURL and am now trying to send a file, getting lost along the way. I'm using a form with a file input. Then would like cURL to send it off to my server. Here is my upload page. <form action="curl_page.php" method="post" enctype="multipart/form-data"> Filename: <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="Submit" /> </form>
Here is my curl page with some issues.
<?php $tmpfile = $_FILES['file']['tmp_name']; $filename = basename($_FILES['file']['name']); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://my_server/file_catch.php"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, true); $data = array( 'uploaded_file' => '@'.$tmpfile.';filename='.$filename, ); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $output = curl_exec($ch); curl_close($ch); ?> The file_catch.php on my server looks like this.
<?php $folder = "audio/"; $path = $folder . basename( $_FILES['file']['name']); if(move_uploaded_file($_FILES['file']['tmp_name'], $path)) { echo "The file ". basename( $_FILES['file']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } ?> Thanks for any help!
error_reporting(E_ALL); ini_set('display_errors','On');at start of each script; Curl errosecho curl_error($curl) . ': ' . curl_errno($curl);aftercurl_execbut beforecurl_close; you also likely want to seeprint_r($_POST); print_r($_FILES);in second script.