filtration script
Posted by: atac (---.ip.telfort.nl)
Date: April 09, 2008 04:27PM

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"winking smiley;
}
?>

<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.

Options: ReplyQuote
Re: filtration script
Posted by: hambuler (---.cpe.net.cable.rogers.com)
Date: April 09, 2008 06:18PM

Replace $HTTP_POST_VARS with $_POST and $HTTP_POST_FILES with $_FILES. It will do the work.

Options: ReplyQuote
Re: filtration script
Posted by: yfastud (Moderator)
Date: April 09, 2008 06:21PM

Your syntax is for older hp version and you should use $_POST for $HTTP_POST_VARS and $_FILES for $HTTP_POST_FILES, for example.

Have fun,

FREE One A Day
FREE Photo
FREE Games
FREE Websites
FREE Portable GPS
FREE WAMP Guides

Options: ReplyQuote
Re: filtration script
Posted by: atac (---.ip.telfort.nl)
Date: April 09, 2008 08:06PM

THANK YOU, LOTS &LOTS. smiling smiley

Options: ReplyQuote
Re: filtration script
Posted by: hambuler (---.cpe.net.cable.rogers.com)
Date: April 09, 2008 08:11PM

Also remove the // slash comments, //<form action="<?php echo(htmlentities($_SERVER['PHP_SELF']))?>" method="POST" enctype=
//"multipart/form-data">
They aren't correct in HTML syntax.

<input type="hidden" name="MAX_FILE_SIZE" value="28480" /> should be included to avoid users waiting to upload a file with large size and then realize that it's waste of time.

Options: ReplyQuote
Re: filtration script
Posted by: yfastud (Moderator)
Date: April 09, 2008 08:21PM

To add what hambuler meant is

<!-- This is an HTML Comment -->

// This is PHP comment

Have fun,

FREE One A Day
FREE Photo
FREE Games
FREE Websites
FREE Portable GPS
FREE WAMP Guides

Options: ReplyQuote


Sorry, only registered users may post in this forum.