note 52157 added to features.file-upload
| From: | oportocala at DON | Date: | Fri, 22 Apr 2005 13:59:59 +0000 |
| Subject: | note 52157 added to features.file-upload | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-88405@lists.php.net to get a copy of this message | ||
I had some problems with uploading files because of the path .So to save you some problems. if you
get an error like "failed to open stream: No such file or directory in ..." it's
likely because your not specifing the full path of the directory you want to upload.In other words
you need to specify the full path and not the relative path in the second parameter.
Here is a small function to upload stuff. The files get their new name via last index from a
database.
<?php
$name_tmp = $HTTP_POST_FILES['file']['tmp_name'];
//read temporay filename
$name = $HTTP_POST_FILES['file']['name'];
//read initial filename
if(is_uploaded_file($name_tmp)){
$ext =explode('.', $name);
$ext = $ext[count($ext)-1];
//get extension of uploaded file
$index=getLastIndex();//costum function
$path_parts = pathinfo(__file__);//get path info of curent php script
$dir = $path_parts['dirname']."\\uploads"; //full path of upload directory
$new = $dir."\\".$index.".".$ext;
if(move_uploaded_file($name_tmp,$new))
echo "File transfer succesfull.";
}
?>
----
Manual Page -- http://www.php.net/manual/en/features.file-upload.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+52157
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52157&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52157&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52157&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52157&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52157&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+52157&report=yes
Search -- http://master.php.net/manage/user-notes.php