Jump to content

php file upload (limit)


westman

Recommended Posts

hi there,i have made lots of working upload scripts and this if from 1 of them that i am having problems with...

if ($_FILES['video_upload']['tmp_name'] != "") {$maxfilesize_vid = 203554432;if($_FILES['video_upload']['size'] > $maxfilesize_vid ) {	    $errorMsg_upload = "Your Video was too large. Must be 22MB or less, please try again.";	    unlink($_FILES['video_upload']['tmp_name']);

here in $maxfilesize_vid i set it to 203554432 is that 22MB?plus i am aware that servers can have upload limits, so i spoke with my server admin and they told me to use... memory_limit = 50Mpost_max_size = 15Mfile_uploads = Onupload_max_filesize = 25M in file name php.ini to get the max file upload to 25MB i am still having problems when i try to upload a file that is 15MB but no problem from a file 3MB large.any help?

Link to comment
Share on other sites

my php.ini file now looks like this... register_globals = offallow_url_fopen = off expose_php = Offmax_input_time = 60variables_order = "EGPCS"extension_dir = ./upload_tmp_dir = /tmpprecision = 12SMTP = relay-hosting.secureserver.neturl_rewriter.tags = "a=href,area=href,frame=src,input=src,form=,fieldset=" memory_limit = 50Mpost_max_size = 200Mfile_uploads = Onupload_max_filesize = 100M when i upload a file that is 10MB it uploads as normal and at 100% uploaded the page refresh's and nothing happens with no positive or negative errors.any help?

Link to comment
Share on other sites

here in $maxfilesize_vid i set it to 203554432 is that 22MB?
No, it's 194MB. 22MB is 23068672 bytes. If you upload a file that is too large though then PHP will indicate that in the error property of the $_FILES array. Other than that, you didn't post enough code to try and guess what is happening or what is supposed to happen.
Link to comment
Share on other sites

sorry for late response my pc broke, am back now i tried 23068672 bytes for 22 MB and i uploaded a file 18 MB with no problem thank you for them numbers ;)last one, could i have the numbers that equal 100 MB so i can upload any file under 100 MB please

Link to comment
Share on other sites

so what could it be? this is my full upload script...

if ($_FILES['video_upload']['tmp_name'] != "") {$maxfilesize_vid = 104857600;if($_FILES['video_upload']['size'] > $maxfilesize_vid ) {	    $errorMsg_upload = "Your Video was too large. Must be 22MB or less, please try again.";	    unlink($_FILES['video_upload']['tmp_name']);}else if (!preg_match("/\.(avi|mp4|wmv|mov|flv|swf)$/i", $_FILES['video_upload']['name'] ) ) {	    $errorMsg_upload = "Your Video was not .avi, .mp4, .wmv, .mov, .flv or .swf and it must be one of those 6 formats, please try again";	    unlink($_FILES['video_upload']['tmp_name']);} else {$find_fileinfo_video = mysql_query("SELECT * FROM vid ORDER BY id DESC LIMIT 1") or die (mysql_error());$find_fileinfo_video_check = mysql_num_rows($find_fileinfo_video);if ($find_fileinfo_video_check == 0){$vid_file_id = "1";}else{while ($row = mysql_fetch_array($find_fileinfo_video)) {$vid_file_id = $row["id"];}$vid_file_id++;}mkdir("vid/$vid_file_id", 0755);$newname1 = "myvid.mp4";if (move_uploaded_file($_FILES['video_upload']['tmp_name'], "video/$vid_file_id/".$newname1)) { $video_image_y_n = "0";if ($_FILES['video_image']['tmp_name'] != "") {$maxfilesize = 43554432;if($_FILES['video_image']['size'] > $maxfilesize ) {	    $errorMsg_upload = "Your Video image was too large. Must be 4MB or less, please try again.";	    unlink($_FILES['video_image']['tmp_name']);}else if (!preg_match("/\.(gif|png|jpg|jpeg)$/i", $_FILES['video_image']['name'] ) ) {	    $errorMsg_upload = "Your Video image was not .gif, .png or .jpg and it must be one of those 3 formats, please try again";	    unlink($_FILES['video_image']['tmp_name']);} else {$newname7 = "myvid.gif";if (move_uploaded_file($_FILES['video_image']['tmp_name'], "video/$vid_file_id/".$newname7)) { $video_image_y_n = "1";} else {$video_image_y_n = "0";}}}////// DB info input here  $updateMsg_upload = "You successfully uploaded a Video.";} else {$errorMsg_upload = "There was an error uploading your video, please try again. If it continually fails, please contact us.";}}}

Link to comment
Share on other sites

i tried using .... class UploadException extends Exception { public function __construct($code) { $message = $this->codeToMessage($code); parent::__construct($message, $code); } private function codeToMessage($code) { switch ($code) { case UPLOAD_ERR_INI_SIZE: $message = "The uploaded file exceeds the upload_max_filesize directive in php.ini"; break; case UPLOAD_ERR_FORM_SIZE: $message = "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form"; break; case UPLOAD_ERR_PARTIAL: $message = "The uploaded file was only partially uploaded"; break; case UPLOAD_ERR_NO_FILE: $message = "No file was uploaded"; break; case UPLOAD_ERR_NO_TMP_DIR: $message = "Missing a temporary folder"; break; case UPLOAD_ERR_CANT_WRITE: $message = "Failed to write file to disk"; break; case UPLOAD_ERR_EXTENSION: $message = "File upload stopped by extension"; break; default: $message = "Unknown upload error"; break; } return $message; }} // Use if ($_FILES['file']['error'] === UPLOAD_ERR_OK) { //uploading successfully done } else { throw new UploadException($_FILES['file']['error']); } near ////// DB info input herein my script but am still not getting any errors. when i upload a file 47 MB in size it gets to 100% and then nothing happens, looks like a page refresh.

Link to comment
Share on other sites

What do you expect to happen instead? does your file is being saved in server? did you check the filesystem? i cant see anything which can output. you also like to use debug statements to ensure what is happening.

Link to comment
Share on other sites

check what move_upload_file() is returning. add some debug statements. if $_FILES['file']['error'] is not showing any error that means it is getting uploaded to server but not geting saved.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...