note 75640 added to function.move-uploaded-file
| From: | dblurred at osu1 dot php dot net | Date: | Sat, 09 Jun 2007 20:54:50 +0000 |
| Subject: | note 75640 added to function.move-uploaded-file | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-127339@lists.php.net to get a copy of this message | ||
I spent days trying to get the temp file to load on my webpage. Then I just tried to access it.
Today I saw this Function, and with the function below called "uploadfile" it worked.
Finding that function and making it work took about 15 minutes! Gotta love posting here.
Here is what I used to take the the image and move it to a directory called TEST under the root. I
stored this image in MySql.
THANK YOU the the author and the one who pointed out the mistake and the one who made it better.
<?php
if ($_FILES['image_upload']['size'] > 0) {
$fileName = $_FILES['image_upload']['name'];
$tmpName = $_FILES['image_upload']['tmp_name'];
$fileSize = $_FILES['image_upload']['size'];
$fileType = $_FILES['image_upload']['type'];
if(uploadfile($fileName,$_SERVER['DOCUMENT_ROOT'].'/test/',$tmpName)) {
print "Received ".$fileName." - its size is ".$fileSize;
} else {
print "Upload failed! ";
}
// Usage:
uploadfile($_FILE['file']['name'],'temp/',$_FILE['file']['tmp_name'])
function uploadfile($origin, $dest, $tmp_name)
{
$origin = strtolower(basename($origin));
$fulldest = $dest.$origin;
$filename = $origin;
for ($i=1; file_exists($fulldest); $i++)
{
$fileext =
(strpos($origin,'.')===false?'':'.'.substr(strrchr($origin,
"."), 1));
$filename = substr($origin, 0,
strlen($origin)-strlen($fileext)).'['.$i.']'.$fileext;
$fulldest = $dest.$filename;
}
if (move_uploaded_file($tmp_name, $fulldest))
return $filename;
return false;
}
?>
----
Server IP: 69.39.81.135
Probable Submitter: 71.103.31.225
----
Manual Page -- http://www.php.net/manual/en/function.move-uploaded-file.php
Edit -- https://master.php.net/note/edit/75640
Del: integrated -- https://master.php.net/note/delete/75640/integrated
Del: useless -- https://master.php.net/note/delete/75640/useless
Del: bad code -- https://master.php.net/note/delete/75640/bad+code
Del: spam -- https://master.php.net/note/delete/75640/spam
Del: non-english -- https://master.php.net/note/delete/75640/non-english
Del: in docs -- https://master.php.net/note/delete/75640/in+docs
Del: other reasons-- https://master.php.net/note/delete/75640
Reject -- https://master.php.net/note/reject/75640
Search -- https://master.php.net/manage/user-notes.php