3

My website does no process data from forms with the enctype="multipart/form-data" set. However the 'php://input' gets the data even if the php manual says it shouldn't be available for the enctype. I think it might be some settings that is wrong but I have no idea which it might be.

Some code:

<?php
    var_dump($_REQUEST);
    echo file_get_contents("php://input");
?>
<form id="slideForm" action="" method="post" enctype="multipart/form-data">
    <input type="text" name="test">
    <input type="submit" name="submit" id="submit" value="ADD"/>
</form>

Update

I have been in contact with the support of the company that host the servers for my website and we have solved the problem. I'm not completly sure on what is the problem but it was somethin funky with their servers and php. I don't work on PHP 7.0 or PHP 5.6 but if I use their native (PHP 5.5) it works without problems.

Community
  • 1
  • 1
Olof
  • 776
  • 2
  • 14
  • 33
  • did you try to add print_r($_POST); to see if you are getting any post? – Aslan Kaya Mar 25 '16 at 17:13
  • Yes I have and it is empty. – Olof Mar 25 '16 at 18:50
  • You will need to submit your
    code and PHP code. its difficult to find what the problem is without looking at the codes
    – Aslan Kaya Mar 25 '16 at 19:44
  • Updated with the code. As i said it's probably not the code. – Olof Mar 25 '16 at 21:25
  • Which web server are you using and how is PHP being served? `php-fpm` or `mod_php` (if server is Apache)? – N.B. Mar 25 '16 at 22:14
  • The server says it's running apache with CGI. – Olof Mar 26 '16 at 12:07
  • http://stackoverflow.com/questions/5077969/php-some-post-values-missing-but-are-present-in-php-input – Axalix Mar 27 '16 at 21:24
  • @Axalix that is close to my problem, his problem was the application/x-www-form-urlencoded wich works just fine for me. – Olof Mar 27 '16 at 21:49
  • What PHP version exactly are you using? – Axalix Mar 27 '16 at 21:51
  • Also can you share your "post_max_size" setting + dbl. check the value is it zero or not, ending with "M" or "MB"? – Axalix Mar 27 '16 at 21:57
  • I'm running on php 7.0 I also have tested on php 5.6. The "post_max_size" is set to 128mb. Sorry i don't really know what dbl means. I don't find any settings named like that. – Olof Mar 27 '16 at 22:42
  • @Olof, can you explain your issue more clear. The problem is not easily recognizable – Nehal Mar 29 '16 at 13:18
  • 1
    @Olof, your action attribute is empty. When you submit, the same page is load. If this page is index.php, the $_POST var can be lost. Ex: http:domain.com/ load the index.php but sometime (.htaccess or server config) the $_POST is lost when the redirection do. Try to change your action attribute and specify explicitly your file like action="yourCurrentScript.php" – Xenofexs Mar 30 '16 at 12:36
  • @Xenofexs I wrote in the update the problem is partially solved. It's a parsing problem with the web-hotel. – Olof Mar 31 '16 at 14:14
  • @Olof. I've not understand your coment. So, your problem is solved ? Do you want I write a response for you can validate ? Do you have try to change your action attribute ? – Xenofexs Apr 01 '16 at 12:51

5 Answers5

0

I don't understand which type of data you want to POST. If it's just a test you should only have:

<?php
    var_dump($_POST);
?>
<form id="slideForm" action="" method="post">
    <input type="text" name="test">
    <input type="submit" name="submit" id="submit" value="ADD"/>
</form>

If you want to POST a file you must have:

<?php
    var_dump($_POST);
?>
<form id="slideForm" action="" method="post" enctype="multipart/form-data">
    <input type="file" name="test">
    <input type="submit" name="submit" id="submit" value="ADD"/>
</form>

Make sure you are able to POST data on your php server. Check these php variables:

upload_max_filesize
upload_tmp_dir
file_uploads
Lord-Y
  • 132
  • 2
  • 8
  • If you don't understand than you could have sent a comment. The reason why I only use a small from is because of debugging the full form does sometimes uppload a file and sometimes just take an URL. – Olof Mar 26 '16 at 12:08
0

In most cases you will not need to use this attribute at all. The default value (i.e. if you don't use this attribute at all) is "application/x-www-form-urlencoded", which is sufficient for almost any kind of form data. The one exception is if you want to do file uploads. In that case you should use "multipart/form-data". Try the following code for echo "test" data.

<?php
    var_dump($_REQUEST);
    echo $_REQUEST['test'];
?>

<form id="slideForm" action="" method="post">
    <input type="text" name="test">
    <input type="submit" name="submit" id="submit" value="ADD"/>
</form>
0

I tried your code, and it is working as expected: the $_REQUEST is populated properly and the php-input is empty.

Considering that your code looks fine, and it is working as expected on my server, i suggest you check your .htacces (or equivalent) for filter/rewrite modules, maybe even server config settings or even page encoding.

99% it's not the code itself.

zedling
  • 638
  • 8
  • 28
0
<?php
    // File data will display here
    print_r($_FILES);
    // OR you can write with condition
    if($_FILES['test']){
       print_r($_FILES);
    }
?>
<form id="slideForm" action="" method="post" enctype="multipart/form-data">enter code here
    <input type="file" name="test">
    <input type="submit" name="submit" id="submit" value="ADD"/>
</form>
  • I wrote in the update the problem is partially solved. It's a parsing problem with the web-hotel. – Olof Mar 31 '16 at 14:15
0

When you send the header Content-Type:multipart/form-data; PHP parses the data from request into $_POST and $_FILES and clears the input buffer. In order to read the input buffer you should remove that header.

Hossein Shahdoost
  • 1,692
  • 18
  • 32