jaArch Posted October 24, 2011 Share Posted October 24, 2011 Hi: Is it possible to use the ereg() function in a file upload script so that the ereg() can recognize whether or not the file type is a .jpg, .gif, .png? I already figured out how to do it without using the ereg() function - but I'm just interested to know if it is possible using ereg()..if so, could you provide me with an example? I'm also a bit confused as to how to use ereg() to recognize file types. Here;s what I've done: function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } if ($image) { $filename = stripslashes($_FILES['image']['name']); $extension = getExtension($filename); $extension = strtolower($extension); if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { echo '<h1>Unknown extension!</h1>'; $errors=1; } Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/249703-using-ereg-in-file-upload-script/ Share on other sites More sharing options...
jaArch Posted October 24, 2011 Author Share Posted October 24, 2011 Anybody? Anybody? Buelller? Quote Link to comment https://forums.phpfreaks.com/topic/249703-using-ereg-in-file-upload-script/#findComment-1281821 Share on other sites More sharing options...
Pikachu2000 Posted October 24, 2011 Share Posted October 24, 2011 ereg is deprecated. Quote Link to comment https://forums.phpfreaks.com/topic/249703-using-ereg-in-file-upload-script/#findComment-1281829 Share on other sites More sharing options...
ManiacDan Posted October 24, 2011 Share Posted October 24, 2011 1) Don't bump, it's against the rules. 2) ereg is deprecated, preg is better. 3) preg can be used to see if the fileNAME ends in a specific three-letter combination, but that doesn't mean anything. All imgur posts are .jpg regardless of their actual filetype. Quote Link to comment https://forums.phpfreaks.com/topic/249703-using-ereg-in-file-upload-script/#findComment-1281833 Share on other sites More sharing options...
jaArch Posted October 24, 2011 Author Share Posted October 24, 2011 What do you mean by ereg has been deprecated? Quote Link to comment https://forums.phpfreaks.com/topic/249703-using-ereg-in-file-upload-script/#findComment-1281858 Share on other sites More sharing options...
litebearer Posted October 24, 2011 Share Posted October 24, 2011 http://www.webopedia.com/TERM/D/deprecated.html Quote Link to comment https://forums.phpfreaks.com/topic/249703-using-ereg-in-file-upload-script/#findComment-1281864 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.