Reputation: 2097
Okay I can't find a good answer to this, how do i check if a file is actually put into a file upload html form with php?
Doing
if (isset($_FILES['new_image']))
Always returns that it's set so that's no good. Any idea?
Upvotes: 1
Views: 78
Reputation: 5920
All you need is the code below:
if(isset($_FILES['new_image'])) {
// code to execute
}
Or alternatively,
if(isset($_FILES['new_image']) && $_FILES['new_image']['size'] > 0) {
// code to execute
}
...and your form tag should include at least
<form enctype="multipart/form-data">
</form>
Upvotes: 3
Reputation: 2076
In php you can check if a string is a image or not with GD's imagecreatefromstring.
This function returns false
if the image isn't supported, so you can check if the image is valid also.
Upvotes: 0