Jump to content

Limit file size on uploads


grahamb314

Recommended Posts

hi all,

 

Does anyonw know how I would limit the size of the file upload to 5mb in the following?

 

$filename = "../../../../shares/shows/{$_SESSION['directory']}";


if (is_dir($filename)) {

echo "Your show folder exists";
echo "<br>";
$allowed_types = array('mp3', 'mp2', 'mp1', 'wav', 'ogg');


	foreach($_FILES as $file_name => $file_array) {


		if (is_uploaded_file($file_array["tmp_name"])) {

		$image_extension = strtolower(str_replace(' ', '', $file_array["name"]));
		$image_extension = explode('.', $image_extension);
		$image_extension = strtolower($image_extension[count($image_extension) - 1]);

			if (in_array($image_extension, $allowed_types)) {

			move_uploaded_file($file_array["tmp_name"], $filename.'/'.$file_array["name"]) or die 		("ERROR: Couldn't copy");
			echo "The File: ".$file_array["name"]."<br/>\n";
			echo "Was uploaded";

			} 	
			else {

				echo "ERROR: You can not upload this type of file. <br> Allowed file types: MP1, MP2, MP3, WAV and OGG.";
			}
		}


}
}

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/129610-limit-file-size-on-uploads/
Share on other sites

The manual explains this

 

The MAX_FILE_SIZE hidden field (measured in bytes) must precede the file input field, and its value is the maximum filesize accepted by PHP. Fooling this setting on the browser side is quite easy, so never rely on files with a greater size being blocked by this feature. The PHP settings for maximum-size, however, cannot be fooled. This form element should always be used as it saves users the trouble of waiting for a big file being transferred only to find that it was too big and the transfer failed.
http://php.net/manual/en/features.file-upload.php

 

The PHP script which receives the uploaded file should implement whatever logic is necessary for determining what should be done with the uploaded file. You can, for example, use the $_FILES['userfile']['size'] variable to throw away any files that are either too small or too big.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.