megamuff
Full Member
  
Posts: 128 Reputation: -12
37 / – / –
Joined: Apr 2003
|
RE: PHP Help, file upload
code: <?php
if ($HTTP_POST_VARS['submit']) {
print_r($HTTP_POST_FILES);
if (!is_uploaded_file($HTTP_POST_FILES['file']['tmp_name'])) {
$error = "You did not upload a file!";
unlink($HTTP_POST_FILES['file']['tmp_name']);
// assign error message, remove uploaded file, redisplay form.
} else {
//a file was uploaded
$maxfilesize=125829120;
if ($HTTP_POST_FILES['file']['size'] > $maxfilesize) {
$error = "file is too large";
unlink($HTTP_POST_FILES['file']['tmp_name']);
// assign error message, remove uploaded file, redisplay form.
} else {
if ($HTTP_POST_FILES['file']['type'] != "image/gif" AND $HTTP_POST_FILES['file']['type'] != "image/pjpeg" AND $HTTP_POST_FILES['file']['type'] != "image/bmp" AND $HTTP_POST_FILES['file']['type'] != "video/mpeg" AND $HTTP_POST_FILES['file']['type'] != "video/quicktime" AND $HTTP_POST_FILES['file']['type'] != "video/x-msvideo" AND $HTTP_POST_FILES['file']['type'] != "image/png" AND $HTTP_POST_FILES['file']['type'] != "application/x-shockwave-flash") {
$error = "This file type is not allowed";
unlink($HTTP_POST_FILES['file']['tmp_name']);
// assign error message, remove uploaded file, redisplay form.
} else {
//File has passed all validation, copy it to the final destination and remove the temporary file:
copy($HTTP_POST_FILES['file']['tmp_name'],"up/".$HTTP_POST_FILES['file']['name']);
unlink($HTTP_POST_FILES['file']['tmp_name']);
print "File has been successfully uploaded!";
exit;
}
}
}
}
?>
<html>
<head>
<title>File Uploader</title>
</head>
<center>
<form action="<?=$PHP_SELF?>" method="post" enctype="multipart/form-data">
<?=$error?>
<br>if a file name has spaces in it, rename the file and take out the spaces before you upload it!!<br>
Choose a file to upload br>
<input type="file" name="file"><br>
<input type="submit" name="submit" value="submit">
</form>
</center>
</body>
</html>
|
|