Re: image upload keeps file name ?
| From: | Midhun Girish | Date: | Thu, 01 Apr 2010 10:10:56 +0000 |
| Subject: | Re: image upload keeps file name ? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-303717@lists.php.net to get a copy of this message | ||
I use the follwing function for moving files:
public function moveFile($file,$targetdir="../uploads/images/")
{
$fileName = $file['name'];
$ext = substr($fileName, strrpos($fileName, '.') + 1);
do
{
$targetfilename=md5(date("m.d.y.h.i.s").basename($fileName)).'.'.$ext;
$fullname=$targetdir.$targetfilename;
}while(file_exists($fullname));
move_uploaded_file($file["tmp_name"],$fullname);
return $fullname;
}
Call the fn as :
foreach($_FILES as $file_name => $filearray)
{
if( $filearray['error']=='')
{
$filenametobestored=moveFile($filearray);
/*Enter name into db here*/
}
}
this will make sure you never over write anyfiles..
Midhun Girish
On Thu, Apr 1, 2010 at 3:25 PM, Ashley Sheridan <ash@ashleysheridan.co.uk>wrote:
> of the web
> root, which will prevent people from maliciously uploadi
>