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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.