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?

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:

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?

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

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()?

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

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?

Issue resolved.

upload_max_filesize was 65m
post_max_size was 3m

upped post_max_size to 70m

Kudos to prit also in solving

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.