0

Me again...

So now I am confused...

I have a form:

        <form action="addanimal_submit.php" method="post" enctype="multipart/form-data" style="padding-left:10px">
            <p>Name: <input type="text" name="name"></p>
            <p>Date of Birth: <input type="text" name="dateofbirth"></p>
            <p>Description: <input type="text" name="description"></p>
            <p>Available For Adoption? 
                <select type="text" name="available">
                    <option value="1" selected>Yes</option>
                    <option value="0">No</option>
                </select>
            </p>
            <p>Image Of Animal:</p>
            <p><input type="file" name="fileToUpload"></p>
            <input type="submit" name="submit" value="Submit Details" />
        </form>

however when I submit it and echo the vars on the new form, none exist. If I get rid of the <input type="file"> then it magically works. What is the catch with having a file upload and additional data in the same form? It seems awful if you have to make a seperate one just for adding an image?

3
Contributors
8
Replies
34
Views
2 Years
Discussion Span
Last Post by Mike Askew
0

Tested the code in my local and it works:

<?php
if($_POST){
    var_dump($_POST);
    var_dump($_FILES);
}
?>
<form action="" method="post" enctype="multipart/form-data" style="padding-left:10px">
    <p>Name: <input type="text" name="name"></p>
    <p>Date of Birth: <input type="text" name="dateofbirth"></p>
    <p>Description: <input type="text" name="description"></p>
    <p>Available For Adoption? 
        <select type="text" name="available">
            <option value="1" selected>Yes</option>
            <option value="0">No</option>
        </select>
    </p>
    <p>Image Of Animal:</p>
    <p><input type="file" name="fileToUpload"></p>
    <input type="submit" name="submit" value="Submit Details" />
</form>

Result:

Attachments Untitled.jpg 57.14 KB
0

receiving script currently is

<?php
    $target_dir = "imageuploads/";

    print_r($_POST);
    print_r($_GET);
    print_r($_FILES);
?>

which prints

Array ( ) Array ( ) Array ( )

Strange that it works on lps's local. Maybe I have a setting wrong somewhere?

0

It also seems to erase any form of echo I have on the page, however if the file upload input isn't involved then echoing works fine...

For example if I run the script you posted lps I just get the blank form and no print outs at all on post

Edited by Mike Askew

0

There is a condition under which $_POST and $_FILES are not populated, it's related to the value of enable_post_data_reading, if this is 0 then it's disabled. Are you including some php script that uses ini_set()?

0

Just tried this code on my work laptop rather than desktop.

It all works as expected on there... something must be messed up with my wamp installation on desktop...

0

Just noticed [16-Jun-2015 11:10:50 Europe/Paris] PHP Warning: POST Content-Length of 3821214 bytes exceeds the limit of 3145728 bytes in Unknown on line 0 in the error logs when I run it on the desktop. Not sure how I change the limit?

0

Issue resolved.

upload_max_filesize was 65m
post_max_size was 3m

upped post_max_size to 70m

Kudos to prit also in solving

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.