php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18250 php can't receive curl made multipart-form posts()
Submitted: 2002-07-09 13:01 UTC Modified: 2002-07-10 22:33 UTC
From: alberty at neptunelabs dot de Assigned:
Status: Closed Package: cURL related
PHP Version: 4.3.0-dev OS: i686-pc-linux-gnu
Private report: No CVE-ID: None
 [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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-07-09 19:45 UTC] sniper@php.net
You're not really uploading any files here, only sending the data in the file. Not a bug in PHP.

Maybe there's some bug in Curl itself?

 [2002-07-10 04:06 UTC] alberty at neptunelabs dot de
Have you really test the script or have you only _read_ the script?

I don't think the problem is libcurl because you can verify the problem with the old 7.9.5 and the current curl cvs tree.

It is only depended with the PHP version!
 [2002-07-10 22:22 UTC] sniper@php.net
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());   

}
?>

 [2002-07-10 22:33 UTC] sniper@php.net
This bug has been fixed in CVS. You can grab a snapshot of the
CVS version at http://snaps.php.net/. In case this was a documentation 
problem, the fix will show up soon at http://www.php.net/manual/.
In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites.
Thank you for the report, and for helping us make PHP better.

It was just 2 extra bytes added to content-length which
made it not be correct and thus the upload 'failed'.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 06 15:01:31 2024 UTC