note 47723 added to features.file-upload
| From: | mxc at moozeek dot com | Date: | Fri, 26 Nov 2004 15:58:08 +0000 |
| Subject: | note 47723 added to features.file-upload | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-81065@lists.php.net to get a copy of this message | ||
For newbies like me who have problems getting the file upload to
work I would like to suggest the following code which uploads and
changes the file permissions so the file can be accessed and used
after uploading.There is no error checking but its easily added.
This is just a copy paste and WORK! code snippet.
Hope it saves some the hours I spendt finding this out!! ;-)
<?php
// Write the name of the directory you are uploading to
$uploaddir = "../images";
// Then allow the file to be read after uploading!
$filename = ($_FILES['file']['tmp_name']);
chmod($filename, 0644);
// Upload
if(is_uploaded_file($_FILES['file']['tmp_name']))
{
move_uploaded_file($_FILES['file']['tmp_name'],
$uploaddir.'/'.$_FILES['file']['name']);
}
//Do something after file is uploaded
// For example go to a page with a success message like here
or just use print() to write something
$updateGoTo = "image-success.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
?>
----
Manual Page -- http://www.php.net/manual/en/features.file-upload.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+47723
Delete -- http://master.php.net/manage/user-notes.php?action=delete+47723&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47723&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47723&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47723&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47723&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47723&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+47723&report=yes
Search -- http://master.php.net/manage/user-notes.php