0

Hey guys I'm working on a file uploader and I have come across a problem. In my code I am checking to see if a file has been selected via the file upload form, here is the form code:

<form method="post" action="actions/save.php?id=<?print($id);?>" enctype="multipart/form-data">
    Listing Photo: <input type="file" name="file"/>
    <input class="add" type="submit" name="submit" value="Save"/>
</form>

The user selects the file to upload then clicks the "Save" button. Now in my uploading code i am trying to check if the file form has been set like this:

$file = $_POST['file'];    
if(isset($file)) {
//Continue

} else {
//Go back    

}

Now my problem is that even if the file input is set (File selected) it goes to the "Go back" part of the code.

Any suggestions or a different way of checking?

Any help is appreciate, Thanks.

3 Answers 3

2

When you upload files through form, you should have $_FILES superglobal array with that file, so try

print_r($_FILES['file'])

to see what it cointains (size, error code, path ...)

Sign up to request clarification or add additional context in comments.

Comments

1

Uploaded files end up in $_FILES, not in $_POST

see: http://nl.php.net/manual/en/reserved.variables.files.php for documentation and examples

Comments

0

You should have access to uploaded files using the $_FILES array. See also the reference documentation.

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.