ra_ie_darkness Posted June 5, 2012 Share Posted June 5, 2012 I'm trying to create a function to upload files on my server It is working fine but the problem is that it doesn't work when I try to upload files larger than 15/20 mb function uploadfile() { global $id; $getid = mysql_query("Select * from user where email='$id'"); while($result = mysql_fetch_array($getid)) { $userid = $result['id']; } $dir = "C:\\xampp\\htdocs\\filehost\\"; $dir.=$userid."\\"; if($_FILES['usr']['size']>2097152) //2megabytes { echo "You cannot upload files greater than 2mb"; } else { if(move_uploaded_file($_FILES['usr']['tmp_name'],$dir.$_FILES['usr']['name'])) { $fname = mysql_real_escape_string($_FILES['usr']['name']); $fsize = $_FILES['usr']['size']; $date = date("Y-m-d"); $dlurl = substr(md5(uniqid()), 0,10); $newdir = mysql_real_escape_string($dir); $fquery = mysql_query("SELECT * from folder where name ='$userid'"); while($row = mysql_fetch_array($fquery)) { $folderid = $row['name']; } echo "File uploaded"; if(!mysql_query("INSERT INTO myfile (fileid,userid,fid,name,size,date,location,dlurl) VALUES ('','$userid','$folderid','$fname','$fsize','$date','$newdir','$dlurl')")) { echo "Identify"; } else { echo "File uploaded"; } } } //echo "File moved"; } I have given a condition which does not allow files larger than 2 mb but instead of getting the message "You cannot upload files greater than 2mb" I get php error messages How can I fix this Quote Link to comment https://forums.phpfreaks.com/topic/263690-problem-with-uploading-huge-files/ Share on other sites More sharing options...
PeoMachine Posted June 5, 2012 Share Posted June 5, 2012 What PHP Errors you get? Quote Link to comment https://forums.phpfreaks.com/topic/263690-problem-with-uploading-huge-files/#findComment-1351486 Share on other sites More sharing options...
smoseley Posted June 5, 2012 Share Posted June 5, 2012 Your ini is probably not allowing you to upload super-large files. This will allow large file upload, but not advisable: ini_set("upload_max_filesize", "10M"); ini_set("post_max_size", "10M"); In fact, you should probably restrict the file size in the browser to prevent bandwidth hogging. Quote Link to comment https://forums.phpfreaks.com/topic/263690-problem-with-uploading-huge-files/#findComment-1351490 Share on other sites More sharing options...
PFMaBiSmAd Posted June 5, 2012 Share Posted June 5, 2012 You cannot set the upload size limits using ini_set statements in a script. Php uses those values before it ever invokes a script. You must set them in the master php.ini (when you have access to it), in a local php.ini (when php is running as a cgi application), or in a .htaccess file (when php is running as an Apache Module.) You would also NEED to set them to larger values if you are using php to process uploaded files, so it would be very advisable to change the php settings. Quote Link to comment https://forums.phpfreaks.com/topic/263690-problem-with-uploading-huge-files/#findComment-1351499 Share on other sites More sharing options...
ra_ie_darkness Posted June 8, 2012 Author Share Posted June 8, 2012 I changed the settings in my php.ini file and it is working now. Thank you Quote Link to comment https://forums.phpfreaks.com/topic/263690-problem-with-uploading-huge-files/#findComment-1352099 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.