note 55057 added to features.file-upload
| From: | hakimu at gmaildotcom | Date: | Sun, 24 Jul 2005 08:06:02 +0000 |
| Subject: | note 55057 added to features.file-upload | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-92368@lists.php.net to get a copy of this message | ||
This is a response to bryan dot fillmer at beasleyallen dot com about renamig files to avoid
ovewriting. it's simple, since the only problem is the extention, there are other ways of doing
the same heres mine
// Where the file is going to be placed temporarly
$target_path = "/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$_FILES['uploadedfile']['tmp_name']; // temp file
$target_path = "upload/";
$oldfile = basename($_FILES['uploadedfile']['name']);
// getting the extention
$pos = strpos($oldfile,".",0);
$ext = trim(substr($oldfile,$pos+1,strlen($oldfile))," ");
//new file name exmaple for a profile image of a user
$newfile = $username . "." . $ext;
// move the file to the final destination
$target_path = $target_path . basename($newfile);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
----
Manual Page -- http://www.php.net/manual/en/features.file-upload.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+55057
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55057&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55057&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55057&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55057&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55057&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55057&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+55057&report=yes
Search -- http://master.php.net/manage/user-notes.php