ted_chou12 Posted January 2, 2007 Share Posted January 2, 2007 [code]<form enctype="multipart/form-data" action="" method="post"><input type="hidden" name="MAX_FILE_SIZE" value="100000" />Choose a file to upload: <input name="uploadedfile" type="file" /><br /><input type="submit" name=submit value="Upload File" /></form><?php if(isset($_POST['submit'])){//checks file extension$filename = $_POST['MAX_FILE_SIZE'];//I am not sure if I got this part right though, i dont know how to get the filename.$ext = explode(".", $filename);if ($ext[1] != "jpg" && $ext[1] != "gif" && $ext[1] != "png" && $ext[1] !="jpeg") //I dont see why this wouldnt work.{echo "The file you uploaded does not have an image extension!";}else {// Where the file is going to be placed $target_path = "images/photo/";/* Add the original filename to our target path. Result is "uploads/filename.extension" */$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); $_FILES['uploadedfile']['tmp_name']; $target_path = "images/photo/";$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";} else{ echo "There was an error uploading the file, please try again!";}}}?>[/code]it doesnt work, I mean the file extension part, anything i upload (even pictures) it echos the message. Link to comment https://forums.phpfreaks.com/topic/32556-solved-my-upload-script/ Share on other sites More sharing options...
trq Posted January 2, 2007 Share Posted January 2, 2007 Its not logical.[code=php:0]if ($ext[1] != "jpg" || $ext[1] != "gif" || $ext[1] != "png" || $ext[1] !="jpeg")[/code]Also, be aware that checking a file type by extension allone is not reliable. You should use [url=http://php.net/getimagesize]getimagesize[/url] to see if a file is an image. Link to comment https://forums.phpfreaks.com/topic/32556-solved-my-upload-script/#findComment-151376 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.