html - Error in uploading image and text file to server using php -


php file :
form action file in php.
successful in uploading images text files producing 'invalid file error'.
may error , how resolve it?

<?php $allowedexts = array("gif", "jpeg", "jpg", "png", "txt"); $temp = explode(".", $_files["file"]["name"]); $extension = end($temp); if ((($_files["file"]["type"] == "image/gif") || ($_files["file"]["type"] == "image/jpeg") || ($_files["file"]["type"] == "image/jpg") || ($_files["file"]["type"] == "image/pjpeg") || ($_files["file"]["type"] == "image/x-png") || ($_files["file"]["type"] == "image/png") || ($_files["file"]["type"] == "text/txt")) && ($_files["file"]["size"] < 20000000) && in_array($extension, $allowedexts))   {   if ($_files["file"]["error"] > 0) { echo "return code: " . $_files["file"]["error"] . "<br>"; }   else { echo "upload: " . $_files["file"]["name"] . "<br>"; echo "type: " . $_files["file"]["type"] . "<br>"; echo "size: " . ($_files["file"]["size"] / 1024) . " kb<br>"; echo "temp file: " . $_files["file"]["tmp_name"] . "<br>";  if (file_exists("c:/inetpub/wwwroot/" . $_files["file"]["name"]))   {   echo $_files["file"]["name"] . " exists. ";   } else   {   move_uploaded_file($_files["file"]["tmp_name"],   "c:/inetpub/wwwroot/" . $_files["file"]["name"]);   echo "stored in: " . "c:/inetpub/wwwroot/" . $_files["file"]["name"];   } }   } else   {      echo "invalid file";   } ?>  

thanks in advance.

i don't think mime type .txt files correct. try txt/plain instead of txt/text in if statement.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -