Uploading files greater than 2Mb on EBS

Hi guys …. Did you anytime try uploading file greater than 2Mb to apache server??????. I know if you are a php developer you must have encountered this issues in while coding solution exist in file php.ini (you can call it holly mother of php).

There are two ways where in you can change the parameters in php.ini file

  1. changing it in script .i.e changing parameters according to your need. This will not update the parameters in the php.ini file but infect will work according to the need of your script. Examples in this case can be considered like putting ini_set(‘display_errors’,1) error_reporting(E_ALL) etc. But there are some parameters which cannot be changed at all, check this link, if the directive is of the type changeable then only it can be changed else it will not be. The parameters which are marked as system are sometimes impossible or is just not useful.
  2. Second way is to directly make change in the php.ini file which is located at etc/php5/apache2/php.ini file. This is one of the effective methods works every time .

So now you people must be thinking what is the big deal in uploading file to the EBS what you have to do is just login to the AWS terminal and change the php.ini file. But that is not that easy in case of EBS, because you must be knowing about autoscaling. In autoscaling what happens is your EC2 instance gets cloned or in case of autoscale down some EC2 instances are deleted, so because of autoscaling and autoscaledown manipulating php.ini file is no more applicable since any instance may get deleted accidentally.

So now what????. The only thing what we can do is change php.ini directives dynamically but how can we achieve that ? On top while writing this post although I said that it is impossible to change the system directive dynamically (it is not possible with php scripting but alternatives are available).

Do you remeber about .htaccess file. This file is life saver for me .I may be in any problem this file always comes handy. SO this issue is craked by same file give her a big hand please. You can make changes in the .htaccess file and the result what you will get is hilarious, believe me it actually works without any efforts and smooth as butter. Working with .htaccess file always gives me pleasure. I am in love with this file now seriuously ….

So u need to add below code snippet in you .htaccess file and you are done for the day.

php_value upload_max_filesize 50M
php_value post_max_size 50M

It really took my half of the day to find this solution (I know it sounds silly for the 2 lines code to take half day)…… and I enjoyed . I always liked coding and now I am loving it. I really love my profession. Hope this hunger of learnning new things everyday never ever dies off.

Thanks for reading patiently ;) I know it was boring but next I promis it will be super boaring ☺:D

Like what you read? Give Ankita Palekar a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.