Jump to content

File Upload


phpretard

Recommended Posts

Can some help me modify this to accept only .jpg or  .gif

 

<input name='uploaded' type='file' size='50' DISABLED /> // FORM FIELD



function findexts ($filename) 
{ 
$filename = strtolower($filename) ; 
$exts = split("[/\\.]", $filename) ; 
$n = count($exts)-1; 
$exts = $exts[$n]; 
return $exts; 
} 

$ext = findexts ($_FILES['uploaded']['name']) ;

$ran = $_SESSION['MemberID'];

$ran2 = $ran.".";

$target = "banners/logos/";

$target = $target . $ran2.$ext;

if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 
{
$E="UPLOADED";
} 
else
{
$E="ERROR UPLOADING";
}

Link to comment
https://forums.phpfreaks.com/topic/122677-file-upload/
Share on other sites

Yes, that's spot on...

 

I'm a bit confused....why do you have a function to find your extension? Have you had a look at $_FILES?

That has all the functions you need...

 

I would suggest you check the extension first before doing anything else because if it isn't correct you won't need to do anything else right ?

Link to comment
https://forums.phpfreaks.com/topic/122677-file-upload/#findComment-633469
Share on other sites

I've always done it like this, for some unknown reason. :P

 

$accepted_extensions = array("jpg","jpeg","png","gif");

$file_extension = explode(".", $_FILES['uploaded']['name']);
if(in_array($file_extension[count($file_extension)-1], $accepted_extensions)){
//Perform file upload
}else{
//Failed to pass extension check.
}

 

That's just me though.

Link to comment
https://forums.phpfreaks.com/topic/122677-file-upload/#findComment-633518
Share on other sites

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.