note 86091 deleted from function.copy by aidan

From: Date: Wed, 15 Apr 2009 12:22:14 +0000
Subject: note 86091 deleted from function.copy by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-153288@lists.php.net to get a copy of this message
Note Submitter: xmediasoftware at hotmail dot com ---- <?php // here is my own version of UploadFile and renameIfExists // sample: UploadPicture($_FILES['picture'],"images/",true); // if the third parameter it is true, UploadPicture overwrites the picture // if it is false, returns the new name and dont overwrites. regards ///////////////////////// function IfExistsRename($file_name, $new_location){ if(substr($new_location,-1,1) != "/"){ $new_location += $new_location . "/"; } if(file_exists($new_location . $file_name)){ $cont = 0; $original_fila_name = $file_name; do{ $file_parts = explode(".",$original_fila_name,2); $file_name = $file_parts[0] . $cont . "." . $file_parts[1]; $cont++; }while(file_exists($new_location . $file_name)); } return $file_name; } function UploadPicture($posted_picture, $new_location, $overwrite){ $file_name =""; if(substr($new_location,-1,1) != "/"){ $new_location += $new_location . "/"; } if(!$overwrite){ $file_name = IfExistsRename($posted_picture['name'], $new_location); }else{ $file_name = $posted_picture['name']; } // checking if it was send it by post if(is_uploaded_file($posted_picture['tmp_name'])){ // Uploading the file with the new name if(!copy($posted_picture['tmp_name'], $new_location . $file_name)){ echo "Unable to copy the file " . $posted_picture['tmp_name'] . " to the server"; }else{ echo "<!-- Field Copied-->"; } }else{ echo "Unable to detect the file source"; } return $file_name; } ?>

« previous php.notes (#153288) next »