11
votes

I seem to get an "Upload HTTP Error" whenever I try to upload images in Magento 1.7's admin. I have the entire media folder/files set to 777, .htaccess info is correct, I'm not using password protection, and this happens in any browser.

Any suggestions are greatly appreciated!

8

8 Answers

16
votes

There are many things that could be causing this issue, but here's a few things you could try:

  • Make sure the /media directory and all subdirectories have your Apache's user's group (usually 'www-data' or 'httpd'):

    sudo chgrp -R www-data /path/to/magento/media
    
  • Make sure the /media directory and all subdirectories have appropriate permissions given to your Apache's user's group:

    sudo chmod -R 775 /path/to/magento/media
    
  • In System->Configuration->General->Web, make sure "Base URL" and "Base Media URL" are correct under both "Secure" and "Unsecure"

    1. In your Magento database, the table core_config_data contains the raw values for your {{secure_base_url}} and {{unsecure_base_url}}

      Make sure these values are correct and have trailing slashes, like http://example.com/

    2. In the system configuration above, make sure those values are correct accounting for the trailing slash in the raw value. This means they should look like {{secure_base_url}}media for example, with no slashes

  • In System->Cache Management, disable caching

  • Take the .htaccess files from a fresh download of your version of Magento (including the .htaccess in your document root, and any .htaccess files in /media and all subdirectories of /media), back up your current .htaccess files, then explicitly copy the fresh .htaccess files to replace them.

    Because .htaccess starts with the '.' character, it will be ignored by certain Linux commands, which can cause people to think they've copied or overwritten a .htaccess file when they actually haven't, so do this carefully.

    Now try again, and if you get the same error, that'll rule out .htaccess.

  • If you're using SSL, try disabling SSL and if you get the same error, that'll rule out SSL

  • Navigate to app/code/local and app/code/community and make note of the namespaces in those directories. Now go to app/etc/modules and edit every *.xml file in that directory matching the namespaces you noted with the following value for the <active> node:

    <?xml version="1.0"?>
    <config>
        <modules>
            <Namespace_*>
                <!-- set this value to "false" -->
                <active>false</active>
                <!-- more nodes here, just leave every
                     node alone except <active> -->
            </Namespace_*>
        </modules>
    <config>
    

    Now try again, and if you get the same error, that'll rule out module conflicts

  • If the images are large enough, you may be restricted by your PHP settings:

    1. Identify your loaded php.ini:

      <?php
      phpinfo(); // Look for "Loaded Configuration File"
      
    2. Edit your php.ini (if you're on Ubuntu it was probably in /etc/php5/apache2/php.ini):

      sudo vi /path/to/php.ini
      
      # Make these three values higher than the filesize of the images you're
      # trying to upload:
      upload_max_filesize = 200M
      post_max_size = 200M
      memory_limit = 200M
      

      Restart your webserver:

      sudo /etc/init.d/apache2 restart
      

If you've gotten this far and nothing has worked, here are some time-intensive things you could do to narrow down what kind of problem it is:

  • Create a fresh install of Magento on the same webserver and test image uploads.

    1. If they still don't work, it's a problem with Apache or PHP configuration (or possibly even version)

    2. If they do work, it was probably a problem with your Magento core files or your Magento configuration or Magento database or Apache virtual host. Take these steps to help determine which:

      1. Create a new database

      2. Delete everything in /path/to/new/magento/var/*

        sudo rm -rf /path/to/new/magento/var/*
        
      3. In your older Magento admin, go to System->Tools->Backups and click Create Backup. Once that's done, go to /path/to/old/magento/var/backup/ and insert your backup into the new database you created:

        mysql -p -u username database_name < backup_file
        
      4. In your new Magento file system, navigate to /path/to/new/magento/app/etc/local.xml and edit it to point to your new database:

        <username>{{db_user}}</username>
        <password>{{db_pass}}</password>
        <dbname>{{db_name}}</dbname>
        
      5. Try image uploads on the fresh Magento install again, and if you get the error, the problem is in your Magento configuration or your Magento database. If you don't get the error, the problem was in your Magento core files or your Apache virtual host.

If you'd like to provide more information, probably the most useful pieces would be a copy of your loaded php.ini, apache2.conf and/or httpd.conf, and copies of your .htaccess files from document root through all subdirectories of /media, with any sensitive information obfuscated of course.

13
votes

To add to chjohasbrouck's answer, you can also get this error from not having the GD PHP extension enabled.

To install on Ubuntu w/ Apache do:

sudo apt-get install php5-gd

and then restart apache.

Further Ubuntu instructions here: http://www.cyberciti.biz/faq/ubuntu-linux-install-or-add-php-gd-support-to-apache/

9
votes

If you have password-protected your root directory using an .htaccess file, remove this protection and try again.

Inside your .htaccess, look for:

AuthName "Restricted Area"
AuthType Basic
AuthUserFile /path/to/your/passwd_file
AuthGroupFile /dev/null
require valid-user

Make sure to re-check your security setting needs, as you might find better ways to protect your site than this one.

2
votes

Wrong permission is issue behind this error. If Changing group to apache/www-data user and changing write permission doesnt solve this. Disable .htpasswd authentication if enabled into .httaccess to do this comment these lines

#AuthType Basic
#AuthName "Password Protected Area"
#AuthUserFile .htpasswd path
#Require valid-user
2
votes

Dealing with the same problem I found that in my case it was an issue with my nginx config.

The default maximum upload size for nginx is 1MB. If you upload larger files you'll see 413 errors in your nginx error log, while Magento will just tell you a non-descriptive "http upload error".

Change or add [client_max_body_size] parameter in nginx.conf, somewhere in the http {} section, like this example where I set the maximum upload size to 200mb:

http {

    client_max_body_size 200m; 

}
2
votes

I had this problem in Magento 1.7 because the image file name "dutchman's_pipe.jpg" contained an apostrophe. I hope this help's someone else.

0
votes

I found another possible reason. In Magento version 1.6.2.0 this occurred because under System --> Web --> Session REMOTE_ADDR and HTTP_USER_AGENT were activated. I switched both again to "no" and this error disappeared (without any other change!)

0
votes

I experienced the same problem on my Ubuntu 10.04 server. It was caused by this particular setting.

Now I made the following change in this file: /etc/apache2/mods-available/fcgid.conf (you must have root access to modify it):

FcgidMaxRequestLen 1073741824

Almost on the end after the last row of Fcgi commands and before the </IfModule> just add:

<IfModule mod_fcgid.c>
    AddHandler    fcgid-script .fcgi
    FcgidConnectTimeout 60
    FcgidMaxRequestLen 1073741824
</IfModule>