Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento "File was not uploaded"

I'm currently using the magento admin interface, trying to upload an image in the "manage products" and I get the error "file was not uploaded" after I browse the file and click "upload file". I've looked on other forums and the main solution I saw were to make sure that php.ini has the following lines...

magic_quotes_gpc = off
short_open_tag = on
extension=pdo.so
extension=pdo_mysql.so

I have Windows/IIS with ISAPI_Rewrite. Is there a max file upload size that I can change somewhere. I'm uploading pictures from my local desktop of size ~100kb. help!

like image 295
John Avatar asked Apr 19 '10 21:04

John


1 Answers

If you check the XHR response in a debugger, you'll see this {"error":"File was not uploaded.","errorcode":666}

This error comes from Varien_File_Uploader::__construct() in lib/Varien/File/Uploader.php

Here are the important parts

<?php

class Varien_File_Uploader
{
    /**
     * Uploaded file handle (copy of $_FILES[] element)
     *
     * @var array
     * @access protected
     */
    protected $_file;

    const TMP_NAME_EMPTY = 666;

    function __construct($fileId)
    {
        $this->_setUploadFileId($fileId);
        if(!file_exists($this->_file['tmp_name'])) {
            $code = empty($this->_file['tmp_name']) ? self::TMP_NAME_EMPTY : 0;
            throw new Exception('File was not uploaded.', $code);
        } else {
            $this->_fileExists = true;
        }
    }
}

Looking back up the trace you see this is called

$uploader = new Mage_Core_Model_File_Uploader('image');

Which is extended from the Varien class, so the Varien_File_Uploader::_setUploadFileId($fileId) will construct the $this->_file array based on the key image, in this case.

So now the problem is why is $_FILES['image']['tmp_name'] empty?

I checked the 'error' field by temporarily changing the exception to

throw new Exception('File was not uploaded. ' . $this->_file['error'], $code);

I got 7, which is Failed to write file to disk. which means it's a permissions issue. Do a phpinfo() to check where your upload_tmp_dir is set to and make sure it's writable.

In my case, I was out of file space in the /tmp dir.

like image 193
Steve Robbins Avatar answered Sep 19 '22 00:09

Steve Robbins