jazz Posted July 1, 2009 Share Posted July 1, 2009 Hi, I am dead in the water with this. I cannot discover the problem. I am trying to upload a file with curl and also pass a text value. It refuses to work. Here 's a test form: http://85.17.135.223/test.php <?php if (!empty($_REQUEST)) { var_dump ($_REQUEST); } ?> <html> <body> <form> <input type="text" name="a" value="value1" /> <input type="file" name="file1" /> <input type="submit" /> </form> </body> And then there 's the php script. $url = 'http://85.17.135.223/test.php'; $file = getcwd().'/'.'step3.php'; $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, array('type' => 'direct', 'file1'=>"@$file", 'a'=>'aaaaa1')); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLINFO_HEADER_OUT, true); $result = curl_exec ($ch); echo curl_error($ch); $info = curl_getinfo($ch); var_dump($info); Here are the headers: POST /test.php HTTP/1.1 Host: 85.17.135.223 Accept: */* Content-Length: 10448 Expect: 100-continue Content-Type: multipart/form-data; boundary=----------------------------b64cdfea8248 It does not work like it does if you do in through the browser. No script output! How can I make this work? Thank you! Link to comment https://forums.phpfreaks.com/topic/164436-php-curl-upload-file/ Share on other sites More sharing options...
johnathanhebert Posted July 1, 2009 Share Posted July 1, 2009 The problem could be related to the "Expect" header that is automatically being added by the curl functions... the server you are posting to may not support it. Try removing it with: curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); http://www.gnegg.ch/2007/02/the-return-of-except-100-continue/ Link to comment https://forums.phpfreaks.com/topic/164436-php-curl-upload-file/#findComment-867374 Share on other sites More sharing options...
jazz Posted July 1, 2009 Author Share Posted July 1, 2009 Thank you for your reply. I added it but to no avail. The Expect header did indeed disapear, but nothing more changed. Here are the new headers: POST /test.php HTTP/1.1 Host: 85.17.135.223 Accept: */* Content-Length: 10495 Content-Type: multipart/form-data; boundary=----------------------------4047ac8569bd Link to comment https://forums.phpfreaks.com/topic/164436-php-curl-upload-file/#findComment-867384 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.