views:

491

answers:

3

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!

A: 

The exact exception/error-message your'e reporting doesn't show up in Magento's source code as a string, so I'm not 100% sure I'm pointing you in the right direction here.

That said, most uploads in magento are handled by the save method on an instantiated object of the Varien_File_Uploader class.

File: lib/Varien/File/Uploader.php
public function save($destinationFolder, $newFileName=null)
{
    $this->_validateFile();

    if( $this->_allowCreateFolders ) {
        $this->_createDestinationFolder($destinationFolder);
    }

    if( !is_writable($destinationFolder) ) {
        throw new Exception('Destination folder is not writable or does not exists.');
    }

    $result = false;

    $destFile = $destinationFolder;
    $fileName = ( isset($newFileName) ) ? $newFileName : self::getCorrectFileName($this->_file['name']);
    if( $this->_enableFilesDispersion ) {
        $fileName = $this->correctFileNameCase($fileName);
        $this->setAllowCreateFolders(true);
        $this->_dispretionPath = self::getDispretionPath($fileName);
        $destFile.= $this->_dispretionPath;
        $this->_createDestinationFolder($destFile);
    }

    if( $this->_allowRenameFiles ) {
        $fileName = self::getNewFileName(self::_addDirSeparator($destFile).$fileName);
    }

    $destFile = self::_addDirSeparator($destFile) . $fileName;

    $result = move_uploaded_file($this->_file['tmp_name'], $destFile);

    if( $result ) {
        chmod($destFile, 0777);
        if ( $this->_enableFilesDispersion ) {
            $fileName = str_replace(DIRECTORY_SEPARATOR, '/', self::_addDirSeparator($this->_dispretionPath)) . $fileName;
        }
        $this->_uploadedFileName = $fileName;
        $this->_uploadedFileDir = $destinationFolder;
        $result = $this->_file;
        $result['path'] = $destinationFolder;
        $result['file'] = $fileName;
        return $result;
    } else {
        return $result;
    }
}

Throw some debugging statements into this function to see if

  1. It's the one being called and is failing

  2. To figure out why it might be returning false (i.e., not uploading the file)

Alan Storm
A: 

I had some issues with adding images a while back, it turned out the flash image uploader was the culprit. I tracked down what swf file it was and replaced it with a newer version of Magento that I downloaded.

If that doesn't help here's a module that will allow you to upload images without the flash uploader. You may at least be able to ensure it's not a flash issue.

zachwood
A: 

In my case, uploader.swf doesn't even contact the server and returns either Upload I/O Error or SSL Error.

I tried using Charles Proxy and "it works"!! i.e. when using a proxy, the uploader.swf now works. Without a proxy it doesn't.

Seems to me the problem is entirely in the SWF Uploader, not on the server at all.

Hendy Irawan