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

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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