Question:
PHP Webform - maximum attachment size and anti-spam?
2009-07-08 05:14:33 UTC
Hi, I have created a php web-form with attachments which is working perfectly. However, I would like some guidance on what I would need to place in the script to disallow files over 1.5mb in size and if possible, could you give guidance on what I need to fill here:

// This two steps to help avoid spam

$headers .= "Message-ID: <".gettimeofday()." TheSystem@".$_SERVER['SERVER_NAME'].">\r\n";
$headers .= "X-Mailer: PHP v".phpversion()."\r\n";

// With message

$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 8bit\r\n";
$headers .= "".$message."\n";
$headers .= "--".$num."\n";

Thanks, your help is very much appreciated.
Three answers:
Oliver
2009-07-08 05:26:17 UTC
I'd recommend checking the file is small enough on the client side first to avoid the problem of trying to upload a file for ages then being told its too big at the end, but for the PHP side you could check at the very end after you've received the complete file using filesize() or you might be able to do some fancy checking in the middle of the uploading process, not sure if the link will help you
2009-07-08 05:27:01 UTC
If your uploading files to the server, you can simply check the size server side, and then refuse to send it if it is too big:



if ($_FILES["file"]["size"]>1500000) {

echo 'Sorry, you're file is too big';

} else {

//Send the message code...

}
2009-07-08 05:23:09 UTC
You look at $_FILES['filename']['size'] and, if it's too large, you tell the user (and delete it).


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...