grahamb314 Posted October 22, 2008 Share Posted October 22, 2008 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 More sharing options...
discomatt Posted October 22, 2008 Share Posted October 22, 2008 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 https://forums.phpfreaks.com/topic/129610-limit-file-size-on-uploads/#findComment-671933 Share on other sites More sharing options...
grahamb314 Posted October 22, 2008 Author Share Posted October 22, 2008 I understand this, but how do I implement it into my code? Link to comment https://forums.phpfreaks.com/topic/129610-limit-file-size-on-uploads/#findComment-672088 Share on other sites More sharing options...
discomatt Posted October 22, 2008 Share Posted October 22, 2008 The manual provides several in-code examples. I'm not here to code for you Link to comment https://forums.phpfreaks.com/topic/129610-limit-file-size-on-uploads/#findComment-672127 Share on other sites More sharing options...
grahamb314 Posted October 22, 2008 Author Share Posted October 22, 2008 Okay, I'll try to read through it again Link to comment https://forums.phpfreaks.com/topic/129610-limit-file-size-on-uploads/#findComment-672128 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.