NOTE: This post covers one particular method of increasing the upload size, and php servers often have other methods of activating a custom php.ini file. This method works on Site 5 shared hosting. We are going to create a custom php.ini file and activate it so your site uses that instead of the defaults. It is important to make sure that the original php.ini settings from your server are also in this file, otherwise php may stop working.

  • Create a file called ‘create_ini.php’ in your web accessible directory (eg: /public_html/).
  • Change xxxx in the following code to the path to your web directory, and the following to the file:


<?php
// Put all the php.ini parameters you want to change below. One per line.
// Follow the example format $parm[] = "parameter = value";
$parm[] = "post_max_size = 200M";
$parm[] = "upload_max_filesize = 100M";
// full unix path - location of the default php.ini file at your host
// you can determine the location of the default file using phpinfo()
$defaultPath = "/usr/local/lib/php.ini";
// full unix path - location where you want your custom php.ini file
$customPath = "/xxxx/xxxx/public_html/php.ini";
// nothing should change below this line.
if (file_exists($defaultPath)) {
$contents = file_get_contents($defaultPath);
$contents .= "\n\n; USER MODIFIED PARAMETERS FOLLOW\n\n";
foreach (
$parm as $value) $contents .= $value . " \n";
if (
file_put_contents($customPath,$contents)) {
if (
chmod($customPath,0600)) $message = "The php.ini file has been modified and copied";
else
$message = "Processing error - php.ini chmod failed";
} else {
$message = "Processing error - php.ini write failed";
}
} else {
$message = "Processing error - php.ini file not found";
}
echo
$message;
?>

<?php phpinfo() ?>

  • Open http://www.yourwebsite.com/create_ini.php
  • You should see ‘The php.ini file has been modified and copied’ then a list of the new php parameters
  • Check that your parameters are now active, in my case they were not, I had to do one final thing:
  • Add the following line to your web directory .htaccess file, again replacing xxxx with the real path to your web directory:


SuPHP_ConfigPath /xxxx/xxxx/public_html/

  • Now run your script again at http://www.yourwebsite.com/create_ini.php
  • You should see the new parameters take effect!
  • Whatever is shown in the php info section, will be reflected in wordpress.

请留言...