note 75640 deleted from function.move-uploaded-file by bjori

From: Date: Sun, 10 Jun 2007 15:21:42 +0000
Subject: note 75640 deleted from function.move-uploaded-file by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-127356@lists.php.net to get a copy of this message
Note Submitter: dblurred Reason: useless ---- 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; } ?>

« previous php.notes (#127356) next »