Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Cannot upload product image files. Temp file doesn’t seem to exist. 
 
Eastgate
Jr. Member
 
Total Posts:  8
Joined:  2008-11-23
 

I’ve got a problem with my new Magento site. When I try to upload an image for a product, I keep getting a “File was not uploaded” message. I had a look at lib/Varien/File/Uploader.php and it appears that this error message shows when the temp file doesn’t exist (here’s the code):

if( !file_exists($this->_file['tmp_name']) ) {
    
throw new Exception($this->_file['tmp_name''File was not uploaded.');
    return;
else {
    $this
->_fileExists true;
}

I did some debugging and looked at the value of $this->_file[’tmp_name’] and it appears normal (e.g. “/tmp/php_upload/phpKAnwTq").

The site is on shared hosting, and I wondered if it was a problem with file uploads on the server, but I tried a simple PHP upload script outside of Magento and it worked just fine. I have also tried the non-Flash “dull upload” extension, and no difference. Using different browsers gives the same result. Permissions are all set correctly to 777.

So it seems to me like the temp file exists on the server, but by the time the script does the check to see if it exists, it no longer exists? Any help or suggestions for this issue would be appreciated!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Eastgate
Jr. Member
 
Total Posts:  8
Joined:  2008-11-23
 

Well, if anyone else has trouble like this, I think I found a solution. It appears that the web server (shared hosting on SmartyHost, an Australian web host) was destroying the temp file before the Magento uploader could finish working with it and move it.

To fix it, I put some hacky code in lib/Varien/File/Uploader.php which moves the temp file from the PHP temp upload directory as soon as possible and puts it in my own temp folder. It then changes the $_FILES[$fileId]["tmp_name"] value to match the path/name of the new temp file I’ve made. After that I just had to change where it normally uses move_uploaded_file() to use copy() instead.

Not a great solution, but it’s all I could think of after being frustrated by this not working for several days. PM me if you want to copy my code.

 
Magento Community Magento Community
Magento Community
Magento Community
 
bizz
Jr. Member
 
Total Posts:  25
Joined:  2008-12-03
 

I just sent you a PM requesting your code, however this fixed the problem for me

Thankyou magento for wasting another 4 hours of my time!!

What solved it for me? I added the following to my php.ini file in my root dir:

upload_tmp_dir = /home/*username*/www/htdocs/*magento folder*/media/tmp/

Hopefully this helps someone, i think i have read every post on the topic!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Eastgate
Jr. Member
 
Total Posts:  8
Joined:  2008-11-23
 

It’s definitely something that can be fixed on the server-side, for anyone who has this issue. The problem I had initially was that I didn’t have access to many PHP settings since it was on shared hosting, but (after I did my hack-code fix) the hosting support was able to adjust it for the shared hosting account I was using. So if you’re on shared hosting and don’t have access to change php.ini then you should probably just see first if support can fix your tmp directory, if this is the problem you’re having.

 
Magento Community Magento Community
Magento Community
Magento Community
 
shinesoftware
Jr. Member
 
Avatar
Total Posts:  21
Joined:  2009-01-22
Italy
 

If you delete the thrown exception the upload works!

function __construct($fileId)
    
{
        $this
->_setUploadFileId($fileId);

        if( !
file_exists($this->_file['tmp_name']) ) { \\ <<<< Seems that the tmp file is deleted before the check
           
# throw new Exception('File was not uploaded.');  \\  <<<<<<<<<<<<<<<< comment this line
           # return;  \\  <<<<<<<<<<<<<<<< comment this line
        
else {
            $this
->_fileExists true;
        
}
    }

regards

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top