Jump to content

Using ereg() in file upload script


jaArch

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/249703-using-ereg-in-file-upload-script/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.