Im trying to write an upload script that only accepts PNG images on upload. The upload script works fine but when I add the png image detection, it breaks.
Here is how I have it set up:
if ($_FILES) {
if ($_FILES["file"]["type"] == "image/png") {
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
} else { echo "Not A PNG…";
}
}
When I upload a PNG image, I get the ‘not a png’ error – any ideas?
It looks like you’re referencing the file wrong in the IF statement:
should be
(“file” needs to be “uploadedfile”)