Dear fellow users,
can anyone help me with this block of code. the code is design( in principle) to filter out files as it is being uploaded. for example if I get the wrong type of file or the size of the file is too large etc. I should get an error
message on my screen, but that is not happening. the script just rans through the motion and stop (i guess) at the end.
<?php
$maxsize = 28480;//set max upload size
if (!$HTTP_POST_VARS['submit']){
//print_r($HTTP_POST_FILES);
$error=" ";
//this will cause the rest of the processing to be skipped
//and the upload form to displays
}
if (!is_uploaded_file($HTTP_POST_FILES['upload_file']['tmp_name']) AND !isset($error)){
$error = "<b> You must upload a file</b><br /><br />";
unlink($HTTP_POST_FILES['upload_file']['tmp_name']);
}
if ($HTTP_POST_FILES['upload_file']['size'] > $maxsize AND !isset($error)){
$error = "<b>Error, file must be less than $maxsize bytes.</b><br /><br />";
unlink($HTTP_POST_FILES['upload_file']['tmp_name']);
}
if ($HTTP_POST_FILES['upload_file']['type'] != "image/gif" AND $HTTP_POST_FILES['upload_file']
['type'] != "image/pjeg" AND $HTTP_POST_FILES['upload_file']['type'] != "image/jpeg" AND
!isset($error)){
$error = "<b> You may only upload .gif or .jpeg files.</b><br /><br />";
unlink($HTTP_POST_FILES['upload_file']['tmp_name']);
}
if (!isset($error)){
copy($HTTP_POST_FILES['upload_file']['tmp_name'], "uploads/".$HTTP_POST_FILES
['upload_file']['name']);
unlink($HTTP_POST_FILES['upload_file']['tmp_name']);
print "Thank you for your upload.";
exit;
}
else{
echo ("$error"
;
}
?>
<html>
<head></head>
<body>
//<form action="<?php echo(htmlentities($_SERVER['PHP_SELF']))?>" method="POST" enctype=
//"multipart/form-data">
<form action="<?php echo(htmlspecialchars($_SERVER['PHP_SELF']))?>" method="POST" enctype=
"multipart/form-data">
//<form action="<?=$PHP_SELF?"> method="POST" enctype="multipart/form-data">
Choose a file to upload: <br />
<input type="file" name="upload_file" size="80">
<br />
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
Can anyone out there help me with this block of code. PLEASE.