html - Invalid File on file upload PHP -
upload_file.php
$allowedexts = array("jpg", "jpeg", "gif", "png", "mp3", "mp4", "wma", "mp4"); $extension = pathinfo($_files['file']['name'], pathinfo_extension); if ((($_files["file"]["type"] == "video/mp4") || ($_files["file"]["type"] == "audio/mp3") || ($_files["file"]["type"] == "audio/wma") || ($_files["file"]["type"] == "image/pjpeg") || ($_files["file"]["type"] == "image/gif") || ($_files["file"]["type"] == "image/jpeg")) && ($_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("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"; } ?>
html
<!doctype html> <head> <title></title> </head> <body> <form action="upload_file.php" method="post" enctype="multipart/form-data"> <label for="file"><span>filename:</span></label> <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="submit" /> </form> </body> </html>
so problem message "invalid file". happens when try upload video type files. when try upload image works charm. i've searched on stackoverflow other video file upload codes , still couldn't find worked. refer question/solution me and/or fix problem appreciated.
extra note
i've tried adding echo "its type " . $_files["file"]["type"];
debug file type being given returns nice white space.
change part
else { echo "invalid file"; }
to
else { echo "invalid file"; echo "its type " . $_files["file"]["type"]; }
now upload files don't work , add types list
Comments
Post a Comment