php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23765 No raw post data from multipart forms
Submitted: 2003-05-22 18:42 UTC Modified: 2003-05-23 18:12 UTC
From: bugs dot php dot com at brome dot com Assigned: pollita (profile)
Status: Closed Package: *General Issues
PHP Version: 4.3.1 OS: Slackware Linux
Private report: No CVE-ID: None
 [2003-05-22 18:42 UTC] bugs dot php dot com at brome dot com
I'm trying to receive HTTP POST file uploads from an embedded device. For some reason, PHP isn't recognizing the file data correctly, and the file data is showing up in $_POST instead of $_FILES. Unlike a bug reported by someone else, the POST vars are coming through just fine.

So I'd like to use $HTTP_RAW_POST_DATA or php://input to parse it manually, but both are empty whenever receiving multipart form-data, which of course is necessary, and is hard-coded into the device.

Trying to make a similar request using a test form and a regular browser, again both $HTTP_RAW_POST_DATA and php://input are empty, but if I simply remove enctype="multipart/form-data" from the form, I can then see the full raw input using both methods.

Here's the test form:

<form enctype="multipart/form-data" action="upload_photo_action.php" method="post">
<p>DirId: <input type=text name="DirId" value="1"></p>
<p>Filename: <input type=text name="Filename"></p>
<p>Send this file: <input type=file name="ImageData"></p>
<input type=submit value="Send File">
</form>

...and here's my config line:

'./configure' '--prefix=/usr/local/apache/php' '--with-jpeg-dir' '--with-mysql=/usr/local/mysql' '--enable-trans-sid' '--enable-track-vars' '--enable-bcmath' '--enable-ftp' '--with-gd' '--with-png-dir' '--with-zlib-dir' '--with-openssl=/usr/local/ssl' '--with-apxs=/usr/local/apache/bin/apxs'

Thanks!

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-05-22 20:06 UTC] sniper@php.net
This is not a bug, neither $HTTP_RAW_POST_DATA or php://input 
contain the POST uploads as those are handled internally
by PHP itself before your script is run.

Some note would be nice somewhere in the manual about this..


 [2003-05-23 10:10 UTC] bugs dot php dot com at brome dot com
Okay, then how can I handle this upload situation? A 50K file is being uploaded, and appearing only as a four-byte string in the $_POST array. PHP is mangling and/or throwing away the file data, and there's no way at all to get at the raw data?? I can't change anything on the client side, because it's hard-coded into a Nokia mobile phone.

Perhaps the bug is in PHP's handling of multipart form data. It would be ideal if this files data appeared in the $_FILES array like it's supposed to. Unfortunately, since you're saying there's no way get at the raw data, I can't show you what it's NOT parsing correctly...

Any thoughts?
 [2003-05-23 10:19 UTC] sniper@php.net
Or it's a bug in Nokia's software, wouldn't be the first.
(with the give info, I'm assuming that)
If it was sending correct data when uploading files, it would 
work fine with PHP and $_FILES. Apparently it isn't.

Keep this as "Documentation problem" for the reason mentioned earlier.

 [2003-05-23 11:31 UTC] bugs dot php dot com at brome dot com
Well, I need to support file uploads from this device - bug or no... This is the Nokia 3650 smartphone with camera - the one they're selling and advertising on TV worldwide. It would be great if PHP supported the feature that lets you upload photos directly to web albums (that's what I'm trying to create). So far, you're saying this is impossible.

Any help would be greatly appreciated!

Below is an example from Nokia's API document that shows what the HTTP POST coming form the phone is supposed to look like. Can you or someone tell me if PHP should or should not be able to recognize and handle this as an HTTP POST file upload?


POST http://www.club.nokia.com/login/uploadImage?ekey=12345 HTTP/1.1 
User-Agent: Photo Uploader (7650/1.0.0) 
Content-Type: multipart/form-data; boundary=AaB03x 
Content-Length: xxxx 

--AaB03x 
Content-Disposition: form-data; name="DirId" 
Content-Type: text/plain; charset=utf-8 

12345 
--AaB03x 
Content-Disposition: form-data; name="Filename" 
Content-Type: text/plain; charset=utf-8 

cap10001.jpg 
--AaB03x 
Content-Disposition: form-data; name="MimeType" 
Content-Type: text/plain; charset=utf-8 

image/jpeg 
--AaB03x 
Content-Disposition: form-data; name="ImageData"; filename="cap10001.jpg" 
Content-Type: image/jpeg 
Content-Transfer-Encoding: binary 

<contents of file> 
--AaB03x--
 [2003-05-23 12:47 UTC] sniper@php.net
Do you have any URLs to that document?

 [2003-05-23 12:48 UTC] sniper@php.net
Assigning to myself, hopefully I can loan one of those phones from a friend.

 [2003-05-23 13:06 UTC] pollita@php.net
I'd like you to try recompiling PHP with upload support completely disabled.

Look for the following line in main/php_content_types.c (it'll be near the top) and simply comment it out or delete it entirely.

{ MULTIPART_CONTENT_TYPE, sizeof(MULTIPART_CONTENT_TYPE)-1, NULL, rfc1867_post_handler },

Recompile like that and rerun a test using:
<?php
$fp = fopen('serverdata.txt', 'w');
fwrite($fp, serialize($_SERVER));
fclose($fp);

copy('php://input', 'logfile.txt');
?>

And show us what you get. (Though since you're uploading a picture feel free to snip the binary data in logfile.txt down to a representative sample)
 [2003-05-23 13:07 UTC] bugs dot php dot com at brome dot com
Here is a link to the Nokia API document:

http://www.forum.nokia.com/main/1,6566,21,00.html

Please let me know if I can help or provide any other info. Thanks!
 [2003-05-23 13:25 UTC] bugs dot php dot com at brome dot com
Unfortunately, I only have access to one server, and it hosts a busy public site (over 4,000 pages per hour) - I can't afford downtime.

I could send you some small PHP files to test with (it requires a 4-step process - the upload is step 4) and send a request from my Nokia 3650 to your test server. Would that work?
 [2003-05-23 14:07 UTC] pollita@php.net
I've sent you via a direct email, a URL for a page which will accept POST file upload data and store detailed request header and content information.  Please have your camera phone send the picture to that URL via HTTP POST upload.

Sniper-
  I'll post the results here as soon as I get them.
 [2003-05-23 16:18 UTC] pollita@php.net
Great! I believe I've found the problem, please send one more test to confirm.
 [2003-05-23 16:31 UTC] bugs dot php dot com at brome dot com
Okay - 2nd test sent.
 [2003-05-23 16:39 UTC] pollita@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot 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 in short time.
 
Thank you for the report, and for helping us make PHP better.

That worked like a charm.  The problem arose from a case sensitivity in the post content subheaders.  Specifically "Filename" was capitalized.  I've changed it to ignore case since the RFC doesn't appear to require it anyway.  Look for this to work in the next snapshot.
 [2003-05-23 18:12 UTC] bugs dot php dot com at brome dot com
Super-excellent! Thank you!
 [2003-11-29 14:07 UTC] sangapum at hotmail dot com
Did you ever finish making your script that uploads images?? Was it entirely in PHP? Wow, I've been looking for this for a while. I actually just downloaded the Nokia 3650 SDK last week and was gonna peep around today to gain any hints. If this has already been done, no use for me to try and accomplish this. Do you have a homepage/website? And are you distributing this software??

Thanks.
ms
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 01 17:01:32 2024 UTC