rondog Posted June 19, 2009 Share Posted June 19, 2009 Can you increase the max file size for an upload through php rather than changing the php.ini? I tried uploading a 15mb file and it didnt work, but if I upload a 1mb file it works so I am assuming thats the problem. Here is my file: <?php $host = "HOST"; $username = "USERNAME"; $password = "PASSWORD"; $db_name = "DATABASE"; $con = mysql_connect($host,$username,$password); if (!$con) { echo "unable to connect to DB"; echo mysql_error($con); exit(); } $db = mysql_select_db($db_name); if (!$db) { echo "unable to open DB"; echo mysql_error($db); exit(); } //data vars $type = $_POST['type']; $projID = $_POST['projectID']; $title = $_POST['itemTitle']; $description = $_POST['itemDescription']; /********************* * upload file *********************/ if (isset($type)) { $query = mysql_query("SELECT MAX(position) AS position FROM projectData WHERE proj_id = '$projID'"); $row = mysql_fetch_assoc($query); $pos = $row['position'] + 1; if ($query) { $addTime = mktime(); $l_sFileName = strtolower( str_replace( " ", "_", basename( $_FILES['Filedata']['name'] ) ) ); $l_sFilePath = "project_data/".$addTime.$l_sFileName; $fname = "project_data/".$addTime.$l_sFileName; move_uploaded_file( $_FILES['Filedata']['tmp_name'], $l_sFilePath ); $sql = mysql_query("INSERT INTO projectData (proj_id,position,type,path,title,description) VALUES ('$projID','$pos','$type','$fname','$title','$description')"); } } else { echo "Go away!"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/162934-solved-increase-upload-file-size-in-php-rather-than-ini/ Share on other sites More sharing options...
Dathremar Posted June 19, 2009 Share Posted June 19, 2009 Use ini_set() Quote Link to comment https://forums.phpfreaks.com/topic/162934-solved-increase-upload-file-size-in-php-rather-than-ini/#findComment-859693 Share on other sites More sharing options...
rondog Posted June 19, 2009 Author Share Posted June 19, 2009 I did some more research and it appears you cannot set 'upload_max_filesize' through ini_set(). It must be set through php.ini, .htaccess or httpd.conf. How would I do that in .htaccess? Quote Link to comment https://forums.phpfreaks.com/topic/162934-solved-increase-upload-file-size-in-php-rather-than-ini/#findComment-859695 Share on other sites More sharing options...
PFMaBiSmAd Posted June 19, 2009 Share Posted June 19, 2009 You can set php settings in a .htaccess file only if php is running as an Apache module. You should probably also set the post max size - php_value upload_max_filesize 100M php_value post_max_size 100M Quote Link to comment https://forums.phpfreaks.com/topic/162934-solved-increase-upload-file-size-in-php-rather-than-ini/#findComment-859698 Share on other sites More sharing options...
rondog Posted June 19, 2009 Author Share Posted June 19, 2009 You can set php settings in a .htaccess file only if php is running as an Apache module. You should probably also set the post max size - php_value upload_max_filesize 100M php_value post_max_size 100M I just tried that and I get a 500 internal server error..does that mean my host isnt running apache? Quote Link to comment https://forums.phpfreaks.com/topic/162934-solved-increase-upload-file-size-in-php-rather-than-ini/#findComment-859701 Share on other sites More sharing options...
Dathremar Posted June 19, 2009 Share Posted June 19, 2009 I failed there :S Sorry, lack of info, thought it could be done with ini_set... my bad Quote Link to comment https://forums.phpfreaks.com/topic/162934-solved-increase-upload-file-size-in-php-rather-than-ini/#findComment-859707 Share on other sites More sharing options...
PFMaBiSmAd Posted June 19, 2009 Share Posted June 19, 2009 500 internal server error..does that mean my host isnt running apache?It means it is not running php as an Apache module. Php is probably running as a CGI application, so you can probably change them in a local php.ini You should actually just check with your web host how to change these particular settings on his server as he may in fact prevent you from changing them at all. Quote Link to comment https://forums.phpfreaks.com/topic/162934-solved-increase-upload-file-size-in-php-rather-than-ini/#findComment-859736 Share on other sites More sharing options...
rondog Posted June 19, 2009 Author Share Posted June 19, 2009 500 internal server error..does that mean my host isnt running apache?It means it is not running php as an Apache module. Php is probably running as a CGI application, so you can probably change them in a local php.ini You should actually just check with your web host how to change these particular settings on his server as he may in fact prevent you from changing them at all. I checked a little bit ago and they said you create a php.ini file and upload it to whatever folder you want the changes in, which I did and it works. I guess it over writes the main php.ini settings. The only reason I want to do this in code is because I will be selling this product so I wanted it as easy as possible. I'll just have to add that to the FAQ/Help section. Thanks for the help. I guess I could say this topic is solved. Quote Link to comment https://forums.phpfreaks.com/topic/162934-solved-increase-upload-file-size-in-php-rather-than-ini/#findComment-859742 Share on other sites More sharing options...
PFMaBiSmAd Posted June 19, 2009 Share Posted June 19, 2009 Your php installation script could check for and write the necessary settings to either a .htaccess file (Apach_module) or a local php.ini (CGI). Quote Link to comment https://forums.phpfreaks.com/topic/162934-solved-increase-upload-file-size-in-php-rather-than-ini/#findComment-859749 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.