Disable Flash uploader in Magento
Explanation
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 tree 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 replacing it with throw new Exception('File was not uploaded. ' . $this->_file['error'], $code);
I got 7, which is Failed to write file to disk. Introduced in PHP 5.1.0.
which means it's a permissions issue.
Solution
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 of my server.
I've always used the No Flash Image Uploader, which worked with CE v1.4 - v1.7 without issue. The module is no longer available via Magento Connect, though its source code is actively maintained (as of Oct. 2016) and is available on GitHub.
You could grab the extension code and just extract the portion that you need if really necessary.