hello guys
i've got this code to download files. And the thing is that i do not why i can download any file whether its size is above or below the value given for max_file_size. According to the code I eventually put which is described below, it should not download any file which has size above max_file_size = 0 bytes. Nevertheless, it still downloads files with size >0. So, any idea about, why this value for max_file_size is not being useful in stopping the download of files with size above 0?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<?PHP
if ($POST['send']) {
if ($
FILES['downfile'] != "none" AND $FILES['downfile']['size'] != 0){
echo "Name: ".$
FILES['downfile']['name']."<BR>\n";
echo "Size: ".$FILES['downfile']['size']." <BR>\n";
echo "Type: ".$
FILES['downfile']['type']." <BR>\n";

	// for Windows
	if (! copy ($_FILES['downfile']['name'], "C:\caca\\".$_FILES['downfile']['name'])) {
		echo "<h2>File could not be copied</h2>\n";
		}
	else
	  echo "great";
	/* for Linux/Unix 
	if (! copy ($_POST['downfile'], "/tmp/".$_POST['file_name'])) {
		echo "<h2>File could not be copied</h2>\n";
		}
	} */
	}
elseif (($_FILES['downfile']['name'] != "none") AND ($_FILES['downfile']['name'] == 0)) {
		echo "<h2>File size exceded exceded</h2>\n";
		}
else {
		echo "<h2>You haven't choose a new file to download</h2>\n";
	}
echo "<HR>\n";
}

?>
<FORM ENCTYPE="multipart/form-data" ACTION="<?php echo $PHP_SELF ?>" METHOD="post">
<INPUT type="hidden" name="MAX_FILE_SIZE" value="0">
<p><b>File to download<b><br>
Example
<INPUT type="file" name="downfile" size="35"></p>
<p><INPUT type="submit" name="send" value="Accept"></p>
</FORM>
</body>
</html>

    The whole MAX_FILE_SIZE thing appears to be problematic, due to spotty browser support in terms of providing file size information to the server with the upload data and apparently no support in terms of preventing the upload itself (not particularly surprising since it is not part of any w3c.org HTML specification).

    The only dependable way to limit the uploads is by setting the PHP upload_max_filesize configuration parameter (in php.ini or a .htaccess file).

      Write a Reply...