how to specify uploaded file size limit

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

how to specify uploaded file size limit

Post by susrisha »

Hello,
I am hosting some files from a hosting site. The limit for uploaded files is about 3MB. For some reason i want the uploaded file size limit to be more than that say 12MB. This i want it for only a single file which processes the uploaded files right? I am not pretty sure of the settings . In my local system i would have changed it in the php.ini configuration file. but i dont think i have access to the config file on the hosting server.

Question:
1. How do i specify the file uploaded size limit for a single page?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: how to specify uploaded file size limit

Post by Benjamin »

You'll want to use ini_set() to increase the upload_max_filesize and possibly post_max_size as well for that particular page.

http://us2.php.net/manual/en/function.ini-set.php
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: how to specify uploaded file size limit

Post by susrisha »

tried the same but failed to get results

Code: Select all

 
ini_set('upload_max_filesize',1300000000);
ini_set('post_max_size',2000000000);
 
Got one more question.. Can i specify like this?

Code: Select all

 
ini_set('upload_max_filesize','13M');
ini_set('post_max_size','20M');
 
Q2:
There are two pages
page1. contains the form to upload the file
page2: processes the upload file

I believe i have to put the above code in page2. Please tell me if i am right?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: how to specify uploaded file size limit

Post by Benjamin »

Yes, this would go on the page processing the uploads:

Code: Select all

 
ini_set('upload_max_filesize','13M');
ini_set('post_max_size','20M');
 
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: how to specify uploaded file size limit

Post by susrisha »

I think this might help. I am using PHP 5.2.5 version

no results yet.
Firstly i thought i should give the actual values instead of giving as '13M' or so.
So i changed to the actual integer values like this.

Code: Select all

 
ini_set('upload_max_filesize',13631488);
ini_set('post_max_size',20971520);
 
Still no use
I echoed the

Code: Select all

echo $_FILES['video']['error'];
Code giving me 1 implying that it exceeded maximum size.

Have further researched into the php manuals for the ini_set() funciton.
http://us2.php.net/manual/en/ini.list.php

I got to know that PHP_IN_ALL implies can be changeable. but what does PHP_INI_PERDIR mean?
Sorry if its off topic but i failed to understand the meaning.

Googled out for a while regarding the same and found that it cannot be changed in ini_set() function for the versions higher than 5.1 or so.

Considering the option of using .htacess but not sure if even that works..
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: how to specify uploaded file size limit

Post by requinix »

You can't change the limits inside the script. By the time the code gets executed the upload will already have happened.

Alter the php.ini file if you have access, otherwise putting

Code: Select all

php_value upload_max_filesize 13M
php_value post_max_size 20M
inside a .htaccess will do the job.

PHP_INI_PERDIR means using .htaccess and php_value like I just gave.
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: how to specify uploaded file size limit

Post by susrisha »

Here are a few things i did
1. Created a .htaccess file
2. Pasted the exact code as given.
3. Restarted the server

No results.
Is there any other OPTIONS i need to set for the htaccess file??
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: how to specify uploaded file size limit

Post by Benjamin »

The syntax for setting it in .htaccess is different. A few google searches and you should be able to find it.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: how to specify uploaded file size limit

Post by requinix »

astions wrote:The syntax for setting it in .htaccess is different. A few google searches and you should be able to find it.
I guess it depends on what "different" means.

http://php.net/manual/en/configuration.changes.php
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: how to specify uploaded file size limit

Post by susrisha »

:drunk: :drunk: :drunk: :drunk: :lol: :lol: :lol:


Finally got it.

In the httpd.conf file i had this

Code: Select all

 
<Directory "D:/Dev/Apache Software Foundation/Apache2.2/htdocs">
AllowOverride AuthConfig
</Directory>
That means it only checks for authentication purpose. Changed it to 
AllowOverride Options AuthConfig
Restarted the server.
 
The .htaccess file looks like this

Code: Select all

php_value upload_max_filesize 13M
php_value post_max_size 20M
 
Working now properly.

Have been :banghead: :banghead: for about three hours .. Will surely post it in my blog. For further usage and reference i shall post the complete solution in a while.

Thanks everyone.
Post Reply