note 14338 added to features.file-upload.php
| From: | john at php-dude dot com | Date: | Fri, 27 Jul 2001 04:00:17 +0000 |
| Subject: | note 14338 added to features.file-upload.php | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-15893@lists.php.net to get a copy of this message | ||
The following example works fine with PHP 4.0.4 on RedHat Linux 7.0 ...
use the absolute path to your upload dir and remember to chmod it to 1777.
// register variables ...
$file = $HTTP_POST_FILES['file']['name'];
$type = $HTTP_POST_FILES['file']['type'];
$size = $HTTP_POST_FILES['file']['size'];
$temp = $HTTP_POST_FILES['file']['tmp_name'];
$size_limit = "100000"; // set size limit in bytes
$allowed_types = array("text/plain","text/html"); // etc.
if ($file){
if ($size < $size_limit){
if (in_array($type,$allowed_types)){
copy($temp, "/full/path/to/upload/".$file);
echo "The file <tt>$file</tt> was sucessfully uploaded";
} else {
echo "Sorry, files of type <tt>$type</tt> are not permitted";
}} else {
echo "Sorry, your file exceeds the size limit of $size_limit bytes";
}}
echo "
<form enctype='multipart/form-data' action=$PHP_SELF method=post>
Upload a file: <input name='file' type='file'>
<input type='submit' value='Upload'>
</form>
";
That's it...
http://www.php.net/manual/pt_BR/features.file-upload.php