File upload in PHP giving error -


i building web app using php.i creating file upload section in having problem.

<form action="upload.php" method="post" enctype="multipart/form-data"> select image upload: <input type="file" name="filetoupload" id="filetoupload"> <input type="submit" value="upload image" name="submit"> </form> 

upload.php:

<?php $target_dir = "images/"; $target_file = $target_dir . basename($_files["filetoupload"]["name"]); $uploadok = 1; $imagefiletype = pathinfo($target_file,pathinfo_extension); // check if image file actual image or fake image if(isset($_post["submit"])) { $check = getimagesize($_files["filetoupload"]["tmp_name"]); if($check !== false) {     echo "file image - " . $check["mime"] . ".";     $uploadok = 1; } else {     echo "file not image.";     $uploadok = 0; } } // check if file exists if (file_exists($target_file)) { echo "sorry, file exists."; $uploadok = 0; } // check file size if ($_files["filetoupload"]["size"] > 500000) { echo "sorry, file large."; $uploadok = 0; } // allow file formats  if($imagefiletype != "jpg" && $imagefiletype != "png" && $imagefiletype !=    "jpeg" && $imagefiletype != "gif" ) { echo "sorry, jpg, jpeg, png & gif files allowed."; $uploadok = 0; } // check if $uploadok set 0 error if ($uploadok == 0) { echo "sorry, file not uploaded.";   // if ok, try upload file  } else {    if (move_uploaded_file($_files["filetoupload"]["tmp_name"], $target_file)) {     echo "the file ". basename( $_files["filetoupload"]["name"]). " has been    uploaded.";  } else {     echo "sorry, there error uploading file.";   }   }   ?> 

it working fine images. when try check happens if upload mp4 file. echo file exists,sorry, jpg, jpeg, png & gif files allowed.sorry, there error uploading file. kindly guide me doing mistake work fine me without having errors. in advance.

it working fine images. when try check happens if upload mp4 file. echo sorry, jpg, jpeg, png & gif files allowed

this limitation because code limits such.

// allow file formats  if($imagefiletype != "jpg" && $imagefiletype != "png" && $imagefiletype !=    "jpeg" && $imagefiletype != "gif" ) { echo "sorry, jpg, jpeg, png & gif files allowed."; $uploadok = 0; } 

if file not of jpg, png, jpeg, or gif won't allow upload.

it echoes file exists

this because file there (wherever directory is), due check:

// check if file exists if (file_exists($target_file)) { echo "sorry, file exists."; $uploadok = 0; } 

sorry, there error uploading file

i cannot see why is. conditional if ($uploadok == 0) set 0 in of other conditionals, , should true , should echo "sorry, file not uploaded".

moving comments ask.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -