php - Unable to upload JPEG file in the server -
i trying upload images in php server using html form. have written following code. not creating problem when upload 'png' file, when upload 'jpeg' images says 'invalid file'. kindly check , guid me.
thanks
<head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>untitled document</title> </head> <body> <form action="file_upload_test2.php" method="post" enctype="multipart/form-data"> <label for="file">filename:</label> <input type="file" name="file" id="file"><br> <input type="submit" name="submit" value="submit"> </form> </body> </html> <?php $allowedexts = array("gif", "jpeg", "jpg", "png"); $extension = end(explode(".", $_files["file"]["name"])); 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"]["size"] < 200000) && 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"] / 200000) . " kb<br>"; // echo "temp file: " . $_files["file"]["tmp_name"] . "<br>"; if (file_exists("upload/" . $_files["file"]["name"])) { echo $_files["file"]["name"] . " exists. "; } else { move_uploaded_file($_files["file"]["tmp_name"], "upload/" . $_files["file"]["name"]); echo "stored in: " . "upload/" . $_files["file"]["name"]; } } } else { echo "invalid file"; } ?>
if host application on linux, should convert extension lower case match strings in $allowedexts
, because linux case sensitive (and not linux).
check how track execution time of each line / block of lines / methods in php? able run script step step , see, problem is.
Comments
Post a Comment