altis88 Posted March 18, 2010 Share Posted March 18, 2010 hey guys, atm im working on my own site. the problem im having is that my photo uploader doesn't want to work. it's displaying the following error message: this has no file extension that ends on: jpg, jpeg, png, gif the script: <?php if (isSet($_POST['new_submit'])){ // file info $map = "../gallery/photo"; $maxsize = 400*1024; $filetypes = array("jpg", "jpeg", "png", "gif"); // function searches for file type function search_extenstion($file){ $extenstion = strtolower(substr(strrchr($file, "."), 1)); return $extenstion; } $temporarily_file = $_FILES['photo_file']['tmp_name']; $name = $map ."/". $_FILES['photo_file']['name']; /* //uitschakelen om lokaal te testen !!!! if (!is_uploaded_file($_FILES['photo_file'])){ //$fout['lokaal_bestand'] = true; //$foutmelding .= "het bestand werd niet opgeladen vanaf uw compute<br />r"; } */ if (!stristr($_FILES['photo_file']['type'], "image")){ $msg_error .= "the file is not an image<br />"; } if ($_FILES['foto']['size'] > $maxsize){ $readable_size = $maxsize / 1024; $msg_error .= "the file is larger than {$readable_size}kB<br />"; } // <-- problem $extensie = search_extenstion($name); if (!in_array($extenstion, $filetypes)){ $msg_error .= "this has no file extension that ends on: " . implode(", ", $filetypes); } if (!isSet($msg_error)){ copy($temporarily_file, $name); } $content = scandir($map); foreach($content as $file){ $extensie = strtolower(substr(strrchr($file, "."), 1)); if (in_array($extensie, $filetypes)){ $list[] = $file; } } } ?> <?php if (isSet($msg_error)) { print $msg_error; } ?> Can you help me? Quote Link to comment https://forums.phpfreaks.com/topic/195650-photo-uploader-script-nott-working/ Share on other sites More sharing options...
Deoctor Posted March 18, 2010 Share Posted March 18, 2010 r u trying this script in the Internet explorer?? if yes then u need to add some more extensions to your script.. pjpeg also using ur script i think u r checking just the extension only, this is a wrong method of finding the file type.. u can do one more thing is that use this inbuilt function mime_content_type u can even try using this script http://www.php.net/manual/en/features.file-upload.php#88959 Quote Link to comment https://forums.phpfreaks.com/topic/195650-photo-uploader-script-nott-working/#findComment-1027980 Share on other sites More sharing options...
PFMaBiSmAd Posted March 18, 2010 Share Posted March 18, 2010 You are having a little trouble with your variable names in the following two lines of code - $extensie = search_extenstion($name); if (!in_array($extenstion, $filetypes)){ If you were developing and debugging php code on a system with error_reporting set to E_ALL and display_errors set to ON in your master php.ini, php would help you by displaying all the errors it detects. You would save a TON of time. There would have been an undefined error message about the $extenstion variable (which is not spelled correctly anyway) since it is not the same variable name as what is being used in the line of code that is setting $extensie. Quote Link to comment https://forums.phpfreaks.com/topic/195650-photo-uploader-script-nott-working/#findComment-1028035 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.