Windows Azure Web Sites: File upload limit for PHP sites hosted on WAWS
upload_max_filesize & post_max_size. Both have the mode PHP_INI_PERDIR as per List of php.ini directives. The default valie for upload_max_filesize 2 MB and for post_max_size it is 8 MB. Below is a snapshot from PHP’s online documentation (List of php.ini directives).
So we know that we can override this setting in .user.ini file as it is allowed as per PHP documentation. So this is how we do it.
NOTE: If you are using custom PHP runtime as described here, then you have complete control over php.ini and can edit the corresponding sections and ignore this blog post.
Pre-requisites:
Download and install FileZilla, Click here to download FileZilla. I f the download link fails then please visit the FileZilla site to download the file: https://filezilla-project.org/download.php Add a sample php page to your WAWS site with the following one line of code:<div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 57.75%; height: 60px; text-align: left; line-height: 12pt; overflow: auto; font-family: "Courier New", courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: rgb(244, 244, 244);">
<?php
phpinfo();
?>
</div>
</h4>
Steps to update the .user.ini file via FTP using FileZilla:
- Go to the Windows Azure Management Portal.
- Click on Web Sites.
- Go to the Site (Running PHP) for which you want to increase the upload file size limit.
- Go to the DASHBOARD page and click on “Download the publish profile”
- Save the file and open it in notepad.exe.
-
The file contains 2
</strong></font> sections, one for Web Deploy and another for FTP.</font> </li> - You can use either method to add a .user.ini file, in this post I will be using FTP.
- Under the <publishProfile> section for FTP make a not of the following values:
- publishUrl
- userName
- userPWD
- Launch FileZilla.
- Go to File Menu —>Site Manager.
- Under Site Manager window click on New Site button and give it a descriptive name.
- Under the General tab set the values for the following accordingly
- Host: Paste the hostname from publishUrl obtained from the publishsettings file above.
- Logon Type: set this to Normal.
- User: Paste the userName obtained from the publishsettings file above.
- Password: Paste the userPWD obtained from the publishsettings file above.
- Click on Connect to connect to the site over FTP.
- Under Remote site: expand ”/” and then expand the site node.
- Click on wwwroot
- Right click and select “Create new file”. enter the name of the file as “.user.ini” (remove quotes).
- Right click the .user.ini and select “View/Edit” to edit the file in notepad.
- Add these lines to the file:
;Maximum size of the files that can be uploaded
;value of post_max_size must be larger than upload_max_filesize </p>upload_max_filesize = 16M
post_max_size = 22M</font></td> </tr> </tbody> </table> </blockquote>- Save it and close the file.
- You will receive a prompt notifying the file content has been changed.
- Select the check box “Finish editing and delete local file” and click on Yes.
- Start and stop the website to force the settings to be read immediately.
- Browse the phpinfo page you created earlier.
- search for the upload_max_filesize/post_max_size.
- You will find this under the Core section.
As seen in the above snippet, the upload_max_filesize directive is reading the values from the .user.ini file.
Thus, we have successfully overridden the PHP runtime settings.
HTH. Until then CIAO!