".tar.gz, .tgz", "application/x-zip-compressed" => ".zip", "application/postscript" => ".ps, .eps", "application/x-tar" => ".tar", "text/plain" => ".html, .php, .txt, .inc (etc)", "image/bmp" => ".bmp, .ico", "image/gif" => ".gif", "image/pjpeg" => ".jpg, .jpeg", "image/jpeg" => ".jpg, .jpeg", "application/x-shockwave-flash" => ".swf", "application/msword" => ".doc", "application/vnd.ms-excel" => ".xls", "application/octet-stream" => ".exe, .fla (etc)", "image/x-ps" => ".ps" ); # these are only a few examples, you can find many more! $allowed_types = array("image/bmp","image/gif","image/pjpeg","image/jpeg","application/postscript"); # -- function form($error=false) { global $PHP_SELF,$my_max_file_size; if ($error) print $error . "

"; print "\n
"; print "\n"; print "\n"; print "\n

Upload a file"; print "\n
NOTE: Max file size is " . ($my_max_file_size / (1024*1024)) . "Mb"; print "\n

"; print "\n"; print "\n

"; } # END form # -- if (!ereg("^4",phpversion())) { function in_array($needle,$haystack) { # we have this function in PHP4, so for you PHP3 people for ($i=0; $i < count($haystack); $i++) { if ($haystack[$i] == $needle) { return true; } } } } # -- function validate_upload($the_file) { global $my_max_file_size, $image_max_width, $image_max_height,$allowed_types,$the_file_type,$registered_types; $start_error = "\nError:\n"; return $error; } else { return false; } } } # END validate_upload # -- function list_files() { global $the_path; $handle = dir($the_path); print "\nUploaded files:
"; while ($file = $handle->read()) { if (($file != ".") && ($file != "..")) { print "\n" . $file . "
"; } } print "
"; } # -- function upload($the_file) { global $the_path,$the_file_name; $error = validate_upload($the_file); if ($error) { form($error); } else { # cool, we can continue if (!@copy($the_file, $the_path . "/" . $the_file_name)) { form("\nSomething barfed, check the path to and the permissions for the upload directory"); } else { list_files(); form(); } } } # END upload # -- ############ Start page print "\n\nUpload example\n\n"; switch($task) { case 'upload': upload($the_file); break; default: form(); } print "\n\n"; ?>