<?php /* This code is loosely based on john@php-dude.com, the post 27-Jul-2001 12:00 at http://www.php.net/manual/en/features.file-upload.php. */
$HTML = NULL;
if(count($HTTP_POST_FILES) > 0){
$allowed_types = array("application/pdf","text/plain","text/html");
$size_limit = "100000"; //bytes
$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"];
$path_info = pathinfo($PATH_TRANSLATED);
//Web server anonymous user must have
//write permissions to this path:
$write_path = $path_info["dirname"] . "/" . $file;
if ($file){
if ($size < $size_limit){
if (in_array($type,$allowed_types)){
if(move_uploaded_file($temp,$write_path)){
$HTML = "<div>The file <tt>$file</tt> was sucessfully uploaded.</div>";
}
else{
$HTML = "<div>The file <tt>$file</tt> upload failed.</div>";
}
}
else {
$HTML = "<div>Files of type <tt>$type</tt> are not permitted.</div>";
}
}
else {
$HTML = "<div>File exceeds the size limit of $size_limit bytes.</div>";
}
}
$HTML .= "\\n";
}
?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html> <head> <meta name=VS_TARGETSCHEMA content="HTML 4.0"> <meta name="editor" content="Bryan Wilhite"> <meta name="reply-to" content="bwilhite@ucla.mednet.edu"> <meta name="keywords" content=""> <meta name="description" content=""> <title>PHP File Upload Test</title> </head> <body> <?php echo $HTML ?> <form enctype="multipart/form-data" action="<?php echo $PHP_SELF ?>" method="POST"> Upload a File: <input name="file" type="file"> <input type="submit" value="Upload"> </form> </body> </html>