note 86091 added to function.copy

From: Date: Thu, 02 Oct 2008 17:59:14 +0000
Subject: note 86091 added to function.copy
Groups: php.notes 
Request: Send a blank email to php-notes+get-144994@lists.php.net to get a copy of this message
// 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; } ---- Server IP: 69.147.83.197 Probable Submitter: 201.130.106.57 ---- Manual Page -- http://www.php.net/manual/en/function.copy.php Edit -- https://master.php.net/note/edit/86091 Del: integrated -- https://master.php.net/note/delete/86091/integrated Del: useless -- https://master.php.net/note/delete/86091/useless Del: bad code -- https://master.php.net/note/delete/86091/bad+code Del: spam -- https://master.php.net/note/delete/86091/spam Del: non-english -- https://master.php.net/note/delete/86091/non-english Del: in docs -- https://master.php.net/note/delete/86091/in+docs Del: other reasons-- https://master.php.net/note/delete/86091 Reject -- https://master.php.net/note/reject/86091 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#144994) next »