Re: image upload keeps file name ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



  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@xxxxxxxxxxxxxxxxxxxx>wrote:

> of the web
> root, which will prevent people from maliciously uploadi
>

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux