2016-10-13

The error ‘There was an error uploading this file to the server’ is often faced by Joomla users while trying to upload a template, extension or a file via the front-end interface.

For instance, when you try to install an Joomla extension using the feature ‘Extensions >> Extension Manager >> Install >> Install from Directory‘, this error can show.

What causes “There was an error uploading this file to the server” error?

The major reason why this error happens is that the file you are trying to upload is of bigger size than the allowed PHP upload limit.

In most servers, especially shared servers, there is a limit set on the maximum file size that can be uploaded to the server.

This limit is set using the parameter ‘upload_max_filesize’ in php.ini, which is the configuration file for PHP in the servers.

When the uploaded file size exceeds the value defined for ‘upload_max_filesize’ in php.ini, file upload fails with the message “There was an error uploading this file to the server”.

Other causes for upload errors could be the wrong setting for the temp directory, incorrect ownership and permissions of folders or open_basedir restriction.

How to fix “There was an error uploading this file to the server” error

To fix this Joomla error during uploads or automatic installations, you need to follow a step-by-step procedure as we will see here:

1. Identify current upload size limit for PHP

The first aspect to verify is the upload size limit for PHP. To know the PHP settings for a website, create a phpinfo file in the directory with the content:

This file, when accessed in the browser, would show the PHP limits for the server and the domain.

Check the values given for the parameters ‘upload_max_filesize’ and ‘post_max_size’. The parameter ‘post_max_size' is the maximum size for all upload data.

Both these parameters should have values higher than the file you are trying to upload. So if they are lower than required, increase their values.

For cPanel users, the option ‘Software and Services -> PHP configuration’ will display the PHP limits for that website.



PHP upload file size limit

Another setting to check is Joomla’s maximum upload size that is set in the Media Manager’s settings and ensure that its given a high value.

2. Increase PHP file upload size limit

Locate the php.ini file location from the phpinfo page and edit the directives ‘upload_max_filesize’ and ‘post_max_size’ to a higher value, say “10M” or more.

The value set for ‘post_max_size’ should be higher than ‘upload_max_filesize’, as it includes all upload limits. These settings are server-wide and require superuser privilege.

Instead of changing the server wide limit, some hosts allow users to override the settings using .htaccess file in their Joomla directory with the content as:

Reload the server configuration by restarting the webserver. Now the increased PHP limits will come into effect and you would be able to successfully upload files without error.



Phpinfo – PHP file upload size limits

3. Correct the permissions and ownership of folders

In cases where the upload error happens even after having enough upload limits set, next option is to check the permissions of directories where the files are to be uploaded.

Joomla should have a temporary directory created to upload the files before transferring them to the destination directory. This temporary directory should be writable by PHP.

The correct permissions for folders in the document root for Joomla are:

The permissions can be changed using the File Manager in cPanel or via backend. In some servers, the temporary directory need to be set in user’s php.ini file as:

4. Check for open_basedir restrictions

The ‘open_basedir’ restriction is used to restrict PHP to access files within certain folders only. If a file is outside the path defined by open_basedir, PHP cannot open it.

So, if the file upload gives error ‘There was an error uploading this file to the server’, then you need to verify if any such restriction is in place for that website or Joomla directories.

Another PHP setting to verify is the ‘max_execution_time‘, which is usually mentioned in seconds. This time should be determined based on the upload speed.

You need to ensure that the max execution time set is long enough to upload the file and copy this from the temp directory to the destination directory.

In short..

Today we saw how to fix the Joomla error “There was an error uploading this file to the server” that happens when trying to use automatic installers or uploaders in Joomla.

Increasing the server limits is not always advisable beyond a certain limit, or else users can end up abusing the server resources.

In cases where there are security or access restrictions to the server to edit the PHP limits, it is also possible to do a work around with manual uploads and installations.

Bobcares assists the website owners who want to install extensions to their Joomla websites and the server owners who want to set PHP upload size within safe limits.

If you’d like to know how to manage your Joomla websites efficiently and with zero downtime, we’d be happy to talk to you.

The post Fix Joomla error: “There was an error uploading this file to the server” appeared first on Bobcares.

Show more