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.

15
  • did you try to add print_r($_POST); to see if you are getting any post? Commented Mar 25, 2016 at 17:13
  • Yes I have and it is empty. Commented Mar 25, 2016 at 18:50
  • You will need to submit your <form> code and PHP code. its difficult to find what the problem is without looking at the codes Commented Mar 25, 2016 at 19:44
  • Updated with the code. As i said it's probably not the code. Commented Mar 25, 2016 at 21:25
  • 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" Commented Mar 30, 2016 at 12:36

5 Answers 5

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
Sign up to request clarification or add additional context in comments.

1 Comment

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.
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>

Comments

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.

Comments

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>

1 Comment

I wrote in the update the problem is partially solved. It's a parsing problem with the web-hotel.
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.