I'm working on a php image upload script and I've run into a weird problem. The files are being successfully uploaded but they're only around 10bytes. Preview gives me the error:
The file 'filename' could not be opened. It may be damaged or use a file format that Preview doesn’t recognize.
Image upload script:
$FileType = $_FILES['picture_file']['type'];
$FileSize = $_FILES['picture_file']['size'];
$FileName = $_FILES['picture_file']['name'];
$Dir = "uploads/";
if($_FILES){
if (($FileType == "image/gif")
|| ($FileType == "image/jpg")
|| ($FileType == "image/jpeg")
|| ($FileType == "image/png")
&& ($FileSize < 2097152)) {
if(move_uploaded_file($_FILES['picture_file']['tmp_name'], $Dir . $FileName === FALSE)){
echo "<div class='alert alert-danger'> Could not move uploaded file to \"uploads" . htmlentities($FileName) . "\"</div>\n";
} else {
mkdir($Dir, 0777);
file_put_contents($Dir . $FileName, $FileName);
echo "<div class='alert alert-success'>Successfully uploaded \"uploads/" .htmlentities($FileName) . "\"</div>\n";
}
} else {
echo "<div class='alert alert-danger'>File must be a JPG, JPEG, GIF or PNG and weigh <2MB. <strong><a class='alert-link' href='/nnash_ex2/'>Start over?</a></strong></div>";
}
}
I really haven't got a clue as to why partial files are being uploaded so a point in the right direction would be greatly appreciated.