uploading php file type with php code -


i have following piece of code uploading different file types onto server. picture files , pdf. trying upload .php file getting error.

$folder      = $_post['folder_name']; $allowedexts = array("gif", "jpeg", "jpg", "png", "pdf", "php"); $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"] == "application/pdf")         || ($_files["file"]["type"] == "application/php")         || ($_files["file"]["type"] == "image/png"))     && ($_files["file"]["size"] < 200000)     && in_array($extension, $allowedexts) ) {     if ($_files["file"]["error"] > 0) {         echo " <div style='position:absolute;left:50%;top:50%;margin-top:-80px;margin-left:-80px;width:300px;height:200px;'>";         echo "<br><br><span style='font-weight:bold;text-decoration:underline;'>return code: " . $_files["file"]["error"] . "</span><br>";         echo "<br><br><input type=\"submit\" value=\"back cms\" onclick=\"location.href='index_upload.php'\">";     } else {         echo "     <div style='position:absolute;left:50%;top:50%;margin-top:-80px;margin-    left:-80px;width:300px;height:200px;'>";         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($folder . $_files["file"]["name"])) {             echo $_files["file"]["name"] . " <br><br><span style='font-weight:bold;text-    decoration:underline;'>already exists</span>.         ";             echo "<br><br><input type=\"submit\" value=\"back cms\" onclick=\"location.href='index_upload.php'\">";         } else {             move_uploaded_file(                 $_files["file"]["tmp_name"],                 $folder . $_files["file"]["name"]             );             echo "<br><span style='font-weight:bold;text-decoration:underline;'>stored in:</span> " . $folder .                 $_files["file"]["name"];             echo "<br><br><input type=\"submit\" value=\"back cms\" onclick=\"location.href='index_upload.php'\">";             echo "     </div>     ";         }     } } else {     echo "     <div style='position:absolute;left:50%;top:50%;margin-top:-50px;margin-left:-50px;width:200px;height:200px;'>";     echo "<span style='font-weight:bold;text-decoration:underline;'>invalid file</span>";     echo "<br><br><input type=\"submit\" value=\"back cms\" onclick=\"location.href='index_upload.php'\">";     echo "     </div>     "; } 

i getting last error show invalid file.

i made tutorial after attempted same task, please have look.

upload file, image or videos

  1. please indent code, easy read , find errors.
  2. we have facility check error has occurred , why.

    $_files["file"]["error"] gives error code can decoded form documentation.

  3. i have used file extension finfo (wwhich has made active doing changes in php.ini file) feel better way check mime type of multipart form data.

  4. i have mentioned errors because of max file upload size, execution time etc parameters set default value in php.ini , have changed make operation success.

  5. always can ask thing confuses or error comes in front after reading this.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -