php - Why does it echo all the errors in the file -


for reason, displays errors when no image uploaded. there away allow on 1 error display depending on error.

thanks

<?php  require 'header.php';  ?>  <center> <?php $target_dir = "uploads/"; $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"] > 5000000) {     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.";     } } ?> 

some ideas...

  • one option have add exit statement after each error. first encountered shown, , script exit.

  • another option store errors in variable , print @ end of script. errors shown.

  • finally can refactor code , have nested condition statements , allow them have 1 error @ time.


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -