|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-07-09 13:01 UTC] alberty at neptunelabs dot de
Hi,
with the current cvs tree, PHP can't receive curl made multipart-form posts.
With 4.2.0 the script received the files,
but in the current version only a post variable is received.
Here is a small php code.
<---SNIP--->
<?php
function post_packet($exchange_url){
$tmpfname = tempnam ('/tmp', 'UP');
if (!empty($tmpfname)){
$fp = fopen($tmpfname, 'wb');
if ($fp!=false){
fwrite($fp, "123\nfoo\0bar");
fclose($fp);
$packet['test_var']='send';
$packet['test_bin']="@$tmpfname";
$curl = curl_init ();
curl_setopt($curl, CURLOPT_URL, $exchange_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $packet);
$result=curl_exec ($curl);
if (curl_errno($curl)>0){
echo "curl error: ($exchange_url) ".curl_error($curl).'<br>';
}
curl_close ($curl);
unlink($tmpfname);
}
}
return $result;
}
$exchange_url=$_SERVER['SCRIPT_URI'];
if (!isset($_POST['test_var'])){
echo "Do POST<br>";
$result=post_packet($exchange_url);
echo $result;
}
else{
if (isset($_FILES['test_bin'])) echo 'file successfully received';
else{
echo 'file missing!!!<br>';
phpinfo();
}
}
?>
<---SNAP--->
I think it is a rfc1867.c or a curl problem, i don't know.
Regards,
Steve
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 06 14:00:02 2026 UTC |
Yes, I really tested it. But I did it again and realized now that you're absolutely right about it..something is broken. The uploaded file shouldn't end up as normal post variable. This script run with PHP 4.2.0 CLI -> works This script run with PHP 4.3.0-dev CLI -> fails In both tests I had Apache 1.3.26 with PHP 4.3.0-dev so it's not the rfc1867.c which is failing here. My test script: curl.php <?php if (!isset($_POST['test_var'])) { $tmpfname = tempnam ('/tmp', 'UP'); if (!empty($tmpfname)) { $fp = fopen($tmpfname, 'wb'); if ($fp !== false) { fwrite($fp, "123\nfoo\0bar"); fclose($fp); $packet['test_var']='send'; $packet['test_bin']="@$tmpfname"; $curl = curl_init (); curl_setopt($curl, CURLOPT_URL, "http://localhost/curl.php"); curl_setopt($curl, CURLOPT_VERBOSE, 1); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $packet); $ret = curl_exec($curl); curl_close ($curl); unlink($tmpfname); echo $ret; } } } else { echo "<br>POST:"; print_r($_POST); echo "<br>GET:"; print_r($_GET); echo "<br>FILES:"; print_r($_FILES); echo "<br>getallheaders():"; print_r(getallheaders()); } ?>