php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26004 $_POST variables not set when using enctype="multipart/form-data"
Submitted: 2003-10-27 10:47 UTC Modified: 2003-11-03 14:06 UTC
Votes:118
Avg. Score:4.6 ± 0.8
Reproduced:97 of 100 (97.0%)
Same Version:24 (24.7%)
Same OS:31 (32.0%)
From: jacknorton101 at hotmail dot com Assigned:
Status: No Feedback Package: *General Issues
PHP Version: 4.3.3 OS: RedHat Linux 9
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jacknorton101 at hotmail dot com
New email:
PHP Version: OS:

 

 [2003-10-27 10:47 UTC] jacknorton101 at hotmail dot com
Description:
------------
The following code works in my local development environment (Win ME, Apache 1.3.2, PHP 4.3.2) but not on my host (RedHat 9, Apache 2.0.4, PHP 4.3.3).
None of the form inputs defined after the <input type="file" size="40" name="userfile"> line are set in $_POST (all of those appearing before are). Therefore $_POST['submitimage'] does not get set.
If I take out enctype="multipart/form-data", or replace it with "multipart/mixed" the $_POST variables are set, but the file is not available.
The following php.ini directives are identical in both the local and host environments:
File_Uploads = On
Upload_Max_Filesize = 2M
Upload_Tmp_Dir = (default)
Post_Max_Size = 8M
In my local environment Register_Globals is Off, and the host environment has them on.

I have searched previous bug reports, and though I have seen similar problems, they all seem to be closed and rectified some time (over a year) ago, but my host is on release 4.3.3 - i.e. later than my dev environment.

Thanks in anticipation, Jack.

Reproduce code:
---------------
....
if(!isset($_POST['submitimage']))
  {....
<form action="<?=$_SERVER['PHP_SELF']?>" enctype="multipart/form-data" method="post"> 
<input type="text" maxlength="60" size="40" name="caption">
<input type="file" size="40" name="userfile">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000"> 
<input type="submit" name="submitimage" value="Submit">
<input type="reset" value="Reset">
<input type="button" onClick="window.close();" name="noaction" value="No Action">
</form>
....
<?php
  }
elseif('Submit'==$_POST['submitimage'])
  { //process file ....


Expected result:
----------------
I would expect the $_POST variables to be set, for example $_POST['submitimage'] should be set and allow the elseif clause to execute.

Actual result:
--------------
Only the $_POST variables defined in lines above the line:
<input type="file" size="40" name="userfile"> get set. The ones below, including $_POST['submitimage'] do not get set.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-10-27 10:51 UTC] moriyoshi@php.net
Check your httpd.conf (probably in /etc/httpd/conf) if there's some directive that limits the maximum length of incoming data.

See bug #22138 for detail
 [2003-11-03 14:06 UTC] sniper@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


 [2006-04-07 08:07 UTC] timecop at gmail dot com
Yes this is still valid.
whats worse, if enctype=multipart/form-data,
NONE of the variables make it into $_POST.

PHP 5.1.2 / linux
 [2006-05-11 21:24 UTC] hostgeekz at gmail dot com
I am having this issue on PHP 5.0.4, and PHP 5.1.4

Exactly the same as stated above,
enctype="multipart/form-data"
 [2006-08-10 06:25 UTC] cometfish at hotmail dot com
Hi, I had this same problem. I spent hours searching the web, but found nothing except this:
------
from http://www.php.net/manual/en/features.file-upload.php
jason
09-Jan-2006 05:08 
Regarding empty $_FILES and $_POST arrays when uploading files larger than post_max_size:
Tucked away in http://us3.php.net/manual/en/ini.core.php#ini.post-max-size is this nugget:
"If the size of post data is greater than post_max_size, the $_POST and $_FILES superglobals are empty. This can be tracked in various ways, e.g. by passing the $_GET variable to the script processing the data, i.e. <form action="edit.php?processed=1">, and then checking if $_GET['processed'] is set."
This may seem like a bug. You'd expect something like UPLOAD_ERR_FORM_SIZE to be set. But you just two empty superglobals.
I've seen it submitted to bugs.php.net twice and it's been marked as bogus both times. 
--------

I saw this, and realised that my MAX_FILE_SIZE hidden form element was missing. Inserting this fixed the problem immediately. My PHP version is 4.4.2. Hope this helps.
 [2007-05-10 08:47 UTC] dlodhia at yahoo dot com
hi, having same problem.

This is working fine with FF, but not with IE.

If its working fine with FF, it could not be problem with PHP.INI or HTTD.CONF.

any suggestion what could be the reason?
 [2007-05-11 04:56 UTC] no_patience at hotmail dot com
I worked around this injecting the values I wanted into the forms "action" statement and using $_GET to extract these values, the file uploading part then extracts its informaion from the POST part.

I was also seeing this happening with both IE and FF
 [2007-07-03 11:34 UTC] info at netsilik dot nl
Althoug I cannot reproduce the error myself some of my custommers experience the bug described above.
And they pop-up in my error-log files

When reguesting a page with the POST method and the enctype is set to "multipart/form-data", the $_POST suberglobal is left empty.

(Post requests without enctype="multipart/form-data" work fine.)

I've recently moved to PHP 5.1.6.
The exact same code worked fine for months on the previous version.


some php.ini settings (same as previous version):
  max_execution_time = 60
  max_input_time = 120
  memory_limit = 24M
  post_max_size = 8M
  file_uploads = On
  upload_max_filesize = 3M

The html-form: (the document is valid XHTML 1.0 Transitional)

<form action="/gallery/saveFile.php" method="post" enctype="multipart/form-data">
  <input type="hidden" name="sessionId" value="0123456789ABCDEF0000000000000000"/>
  <input type="hidden" name="albumId" value="123"/>
  <input type="hidden" name="MAX_FILE_SIZE" value="3145728"/>
  
  <input type="text" name="title" value="" maxlength="64"/>
  <input type="file" name="userFile"/>
  <input type="checkbox" name="overwerite" value="true"/>
  <input type="submit" value="Upload"/>
</form>

I've not yet found a solutions for this VERY SERIOUS problem
If there is anyone that has a fix, please let me know.
 [2007-07-14 16:15 UTC] mgo dot netmail at gmail dot com
Yup, have the same problem with PHP 5.1.6.
If someone have a fix for this issue please let me know. I recently update my environment and this is starting to cost me too much time and money.

Thanks in advanced.
 [2007-08-03 22:51 UTC] m_ellingham at hotmail dot com
I had this problem and had to raise realpath_cache_size from 16k to 128k. No problems so far.
 [2007-08-08 15:03 UTC] marcel at cohnen dot nl
I have experienced the problem.

The solution provided on this page worked for me. I had a form with a lot of textboxes, and also six fileboxes. Changing the enctypes resulted in either the textboxes working and the fileboxes not working, and vice versa, but no combination so both would work.

My max file size in php.ini was set to 64M which should be enough.

<form action="test.php" method="post" enctype="multipart/form-data" name="form" id="form">
<input type="hidden" name="MAX_FILE_SIZE" value="50000000">

IMPORTANT:
adding the MAX_FILE_SIZE to my form was the solution to the problem. But I discovered a new problem doing this, I had to set the MAX_FILE_SIZE directly under the <form> tag, unlike some other people's examples on this page. Doing this It worked fine for me.

for the record, i am running PHP/4.4.7 Apache/1.3.37 on Fedora 5 running kernel  2.6.20-1.2316.fc5smp
 [2007-12-23 04:36 UTC] mondo at mondomx dot com
Been a while since anyone posted. But I am still having this trouble. I have tried all the solutions on the thread and nothing works.

PHP Version 5.2.4, Apache 2.2.6
 [2008-01-17 21:26 UTC] emmcmahon at comast dot net
I just experienced this problem NOT using enctype="multipart/form-data" - although I have data being passsed simultaneously with Adobe Spry.  I used the recent solution <input type="hidden" name="MAX_FILE_SIZE" value="50000000"> worked for me.
 [2008-01-25 00:06 UTC] jareeq at op dot pl
Same problem in apache 2.2.8 , php 5.2.4 on the begining i'v suspected mod_auth_sspi instaled on my apache but after disabling it error still appears.
Behaviour is strange - if wait aprox 10s betwen submits of form all works fine fast submit of form immediately after it appears generates this problem. The same issue on apache 2.2.8 on windows/linux (XP pro and slackware), `enctype="multipart/form-data"` include - don't matter. Additionaly tested on windows IIS 5.1 with the same configuration (php.ini) of PHP (isapi module)- no problem.
 [2008-02-11 17:17 UTC] w dot antonia at beacon dot e-sussex dot sch dot uk
Apache 2.2.4 and PHP 5.2.4 SuSE 10.3

Problems uploading files

With enctype="multipart/form-data": $_POST variable set but contains no array keys.

print_r(array_keys($_POST));

Prints: Array()

Without enctype="multipart/form-data": $_POST variable set and contains array keys, but no file data as expected for upload.

Help.
 [2008-02-12 13:42 UTC] sri dot www at gmail dot com
I am facing the similar problem. when i upload a file having more than the size specified in post_max_size variable, the $_POST variables are empty after form submission. If i increase the post_max_size variable more than the file trying to be uploaded then i can get the $_POST variables array.

Is there any other way to fix this without relaying php configuration variables in order to get the $_POST variables as it is?
 [2008-03-05 14:43 UTC] schefer at webdessert dot ch
I have experienced the same problems with PHP 5.2.4 on Windows. The solution was to specify the forms method as GET, and not as POST. It worked as well by not specifying any method, as this will choose GET as the default method.

Use it like this:
<form action="myFile.php" enctype="multipart/form-data" method="GET">
 <input type="hidden" name="foo" value="bar" />
 <input type="file" name="file" />
 <input type="submit" value="Upload" />
</form>

print_r($_GET) results in:

Array ( [foo] => bar [file] => abc.zip )
 [2008-03-05 14:56 UTC] schefer at webdessert dot ch
To correct my above message:

Post the form with method GET does not work, setting the post_max_size in php.ini higher than the size of the uploaded file did the trick.
 [2008-09-16 01:58 UTC] mike dot dygert at adelphia dot net
I am having this issue, none of the above worked for me... anybody have other ideas?  (IIS 6, PHP 5.2.6)

Thanks
 [2008-12-15 02:28 UTC] ray_linn at hotmail dot com
occurs the same issues on apache 2.2.8 + latest php 5.2.8, all of the solution above is useless.
 [2009-01-20 14:31 UTC] paraporquerias at yahoo dot com
My problem is that, in my earlier php instalation, I had register_globals=on, and now, with PHP5, it comes off by default:

http://cn.php.net/manual/en/language.variables.external.php

My solution was using this line before I need the value of $username

$username = echo $_POST['username'];

I hope it helps...
 [2009-07-01 16:22 UTC] shaharjourno at hotmail dot com
Hi I had the same bug i found a solution please check your Post_max_SIZE. there are some problems with some sizes. I managed to create this problem and then solved 
Here is a link with some examples

http://forums.devnetwork.net/viewtopic.php?f=31&t=94754
Hopefully it will help .
 [2009-09-10 10:53 UTC] just at helping dot com
IT IS NOT a BUG. GET and post methods will work as normal requests but if you use the form enctype multipart then you got to handle the request as multipart. In java I use the oreilly MultipartRequest to parse the data and it works wonderfully. You migh thave to find a way to get it in PHP or you can write yourself a multipartrequest class based on oreilly's one.
 [2010-02-03 16:17 UTC] gimi dot alb at gmail dot com,
Some Apache hosts have problem parsing variables from .htaccess files.
They do not throw any error, but they just unset the variables. 
I had the problem with the POST variable not being set, when I migrated to a new host. After hours of debugging, I found out that 
these variables:
 #php_value upload_max_filesize 			50M
 #php_value post_max_size 		            55M
 #php_value memory_limit 	               384M
were causing the webserver to set the memory limit to 256K and POST variable not working.
So I commented them out and insted used php.ini to set the variables.
It worked fine after that.
 [2010-02-13 12:57 UTC] sudeshkmr at yahoo dot com
I faced the same problem and nothing worked. I have tested on Apache 2.2, PHP 5.3 on Windows Vista. I also tested on Ubuntu (Karmic) with Apache 2.2 and PHP 5.3. I also tested with nGinX 0.8 and PHP 5.3.

Then I found a workaround. The action="" parameter should not be the script page itself on which you have file upload form. For example, you have a page index.php with the upload form.

<form action="upload.php" enctype="multipart/form-data" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="200000"> 
<input type="file" size="40" name="upload">
<input type="submit" value="Upload">
</form>

The action="upload.php" <-------- This page has to be different than the file upload form page, and it works on all configurations of PHP!

Do not use <php?=$_SERVER['PHP_SELF']?> for the action parameter.
 [2011-03-28 02:15 UTC] mzbirka at centrum dot cz
Just for the record, in my case similar behavior was observed and the cause was 
restrictions in the suhosin - hardened debian distribution, 
suhosin.post.max_name_length specifically.
 [2011-10-11 12:33 UTC] seyhun_cavus at hotmail dot com
Here is the fix: Check the message of gimi.
[2010-02-03 16:17 UTC] gimi dot alb at gmail dot com,

Also you should check (into begin of your script)
"post_max_size, upload_max_filesize, memory_limit"
values to work correctly and safely!

For Example:
http://www.php.net/manual/en/features.file-upload.php#73762

YOU SHOULD CHECK:
================================== 
ini_get('post_max_size');
ini_get('upload_max_filesize');
ini_get('memory_limit');
================================== 

Regards.
 Seyhun Cavus.
 [2019-07-30 16:25 UTC] luckyranger at gmail dot com
WEll it is not a bug and I figured out that I had not set the "name" attributes for the input elements that I was trying to access.

also $_REQUEST['element-name'] works better.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Oct 05 19:01:27 2024 UTC