note 65955 deleted from function.file-exists by danbrown

From: Date: Thu, 18 Feb 2010 14:39:00 +0000
Subject: note 65955 deleted from function.file-exists by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-166145@lists.php.net to get a copy of this message
Note Submitter: sirarthur at sirarthur dot info ---- The following code will rename an uploaded image to a MD5 hash with a rand number added of its name and check wheter a file with same hash already exists or not: <?php $file = $HTTP_POST_FILES['file']; $image=new Image($imgfld,$file); if($image->FType != null){ if ($image->FType=="image/gif") { $ext = ".gif"; }else{ $ext = ".jpg"; } $nfile = md5($image->Name . rand()); while(file_exists($imgfld . $nfile . $ext) == true){ $nfile = md5($image->Name . rand()); } $image->ResizedWidth = $imggrx; $image->ResizedHeight = $imggry; $image->Resample($nfile); ?> It uses an image class found at phpclasses.org

« previous php.notes (#166145) next »