php - How to upload ONLY images in database -


i want upload pictures , in database using php. tried is,

<?php  if (isset($_post['upload'])) {     $con = mysql_connect("localhost", "root", "");     if (!$con) {         die('could not connect: ' . mysql_error());     }      mysql_select_db("iis", $con);     $image = $_files["product_image"]["name"];     $imagetype = mysql_real_escape_string($_files["product_image"]["type"]);     if (substr($imagetype, 0, 5) == "image") {         if (!file_exists("product_images")) {             mkdir("product_images");         }          if ($_files["product_image"]["error"] > 0) {             $error = "error return code :" . $_files["product_image"]["error"] . "<br />";         } else {             move_uploaded_file($_files["product_image"]["tmp_name"], "product_images/" . $_files["product_image"]["name"]);         }     }      $username = $_session['id'];     $product_image = ("product_images/" . $_files["product_image"]["name"]);     mysql_query("insert `feedbackzxc` values ('', '$username', '$product_image')");     echo "image uploaded!"; } else {     echo "only images allowed"; }  ?> 

but when upload file other images doesn't show error message. how can make show error message if file other image uploaded?

your else block message only images allowed shown must located after if block check this: substr($imagetype,0,5) == "image"

if(substr($imagetype,0,5) == "image"){     if(!file_exists("product_images"))     {         mkdir("product_images");     }     if($_files["product_image"]["error"] > 0)     {         $error = "error return code :" . $_files["product_image"]["error"] . "<br />";     }     else     {           move_uploaded_file($_files["product_image"]["tmp_name"], "product_images/".          $_files["product_image"]["name"]);       } } else {     echo "only images allowed"; } 

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -