note 14338 deleted from features.file-upload by irc-html
| From: | irc-html@php.net | Date: | Sat, 19 Jan 2002 20:34:15 +0000 |
| Subject: | note 14338 deleted from features.file-upload by irc-html | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-25361@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...