December 19, 2010

When uploading, where do I set the php.ini parameters?

Question by gAMBOOKa

In the script where the upload form is, or the script that processes the action?

Example parameters:

memory_limit

EDIT: Ok, let me clarify. First, I didn’t know the 2nd, 3rd and 4th parameter could not be changed using ini_set(). Now, I want to know where exactly I should call the ini_set() function. In the form script or the action handling script?

Here’s an example to illustrate what I’m looking for:

form.php

<form action="post.php">
  <input type="text" name="search" />
  <input type="submit" />
</form>

post.php

<?php //handle search ?>

So under which file must my ini_set() function should go?

Answer by Starx

You have to set these parameters initially from php.ini. You cannot change this from a PHP script except memory_limit, for the remaining Just search for those keys you mentioned in php.ini and change their values.

For memory_limit you can use following snippet at your processing page handling the uploads like in your case at post.php

ini_set("memory_limit","16M");

OR

You can create a .htaccess file at the root directory, if your server support mod_rewrite modules you can change them like this

php_value upload_max_filesize 20M
php_value post_max_size 20M
php_value max_execution_time 200
php_value max_input_time 200
...

Please fill the form - I will response as fast as I can!