Magento "File was not uploaded"

I am currently using the magento admin interface trying to upload an image to "manage products" and I get a "file was not uploaded" error message after I view the file and click "upload file". I was looking at other forums, and the main solution I saw was to make sure 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 maximum file upload size that I can change somewhere. I am uploading photos from my local desktop ~ 100KB in size. help!

+4
source share
7 answers

If you check the XHR response in the debugger, you will 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, you see what it's called

 $uploader = new Mage_Core_Model_File_Uploader('image'); 

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

So now the problem. 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 Failed to write file to disk. , which means this is a permission issue. Do phpinfo() to check where your upload_tmp_dir installed and make sure it is writable.

In my case, I did not have the file space in the /tmp .

+5
source

The exact error / error message of your message does not appear in the Magento source code as a string, so I'm not 100% sure that I'm pointing you in the right direction.

However, most downloads in magento are handled by the save method on an instance 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 debug statements into this function to see if there are any

  • This is the one that is invoked and fails

  • To find out why it can return false (i.e. do not upload the file)

+1
source

I had some problems adding images some time ago, it turned out that the flash downloader was the culprit. I kept track of what the swf file was, and replaced it with a newer version of Magento that I downloaded.

If this does not help here is a module that will allow you to download images without a flash downloader. You, at least, can provide it with non-flash memory.

0
source

In my case, uploader.swf does not even contact the server and returns either an I / O loading error or an SSL error.

I tried using Charles Proxy and it works !! that is, when using a proxy server, uploader.swf now works. This is not the case without a proxy server.

It seems that the problem is entirely in the SWF loader, and not on the server at all.

0
source

check if your vhost is enabled:

 php_admin_value home_dir xxxxxxxxxxxxxx 

So upload_tmp_dir must be included in this root directory, otherwise magento functions can not catch tmp_file

for example: your vhost configuration includes home_dir / home / someone

and php.ini upload files to / tmp

/tmp not in the home_dir directory and uses the class function file_exists() php cant read / tmp /

you must create / home / someone / tmp

and enable vhost in configuration

php_admin_value upload_tmp_dir /home/someone/tmp

apache2 reload

Hi

0
source
  if (isset($_FILES['cv']['name']) && $_FILES['cv']['name'] != '') { try { $uploader = new Varien_File_Uploader('cv'); $uploader->setAllowedExtensions(array('doc', 'docx','pdf')); $uploader->setAllowRenameFiles(true); $uploader->setFilesDispersion(false); $path = Mage::getBaseDir('media') . DS . 'jobs' . DS ; if(!is_dir($path)){ mkdir($path, 0777, true); } $uploader->save($path, $_FILES['cv']['name'] ); $newFilename = $uploader->getUploadedFileName(); echo "<br />new file name is = ".$newFilename; } catch (Exception $e) { $error = true; echo "<pre>"; print_r($e); echo "</pre>"; } } 
0
source
  • Change browser, computer, clear local cache and cookies, etc.
  • Check permissions for / media / folder (tried 777 and 755).
  • Read and make changes to .htaccess for GoDaddy servers as described in the .htaccess file in the root directory of Magento
  • The storage is disabled, the cleared cache is removed from Magento, the remote cache is from / var / cache /, and then the storage mode is turned on again, the cleared cache again
  • An earlier version of Prototype.js is loaded and called
  • I downloaded the local version of jQuery when I read that Prototype and jQuery could conflict, and that was the proposed solution.
  • Checked that the GD extension is installed on my PHP build server.
-1
source

Source: https://habr.com/ru/post/1307392/


All Articles