Joh*_*ohn 4 php file-upload image magento
我目前正在使用magento管理界面,尝试在"管理产品"中上传图像,我在浏览文件并单击"上传文件"后收到错误"文件未上传".我看过其他论坛,我看到的主要解决方案是确保php.ini有以下几行...
magic_quotes_gpc = off
short_open_tag = on
extension=pdo.so
extension=pdo_mysql.so
Run Code Online (Sandbox Code Playgroud)
我有带ISAPI_Rewrite的Windows/IIS.是否有最大文件上传大小,我可以在某处更改.我正在从我当地的桌面上传大小~100kb的图片.救命!
如果在调试器中检查XHR响应,您将看到这一点 {"error":"File was not uploaded.","errorcode":666}
此错误来自Varien_File_Uploader::__construct()于lib/Varien/File/Uploader.php
这是重要的部分
<?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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
回顾一下你看到的痕迹
$uploader = new Mage_Core_Model_File_Uploader('image');
Run Code Online (Sandbox Code Playgroud)
这是从Varien类扩展的,因此在这种情况下,Varien_File_Uploader::_setUploadFileId($fileId)将$this->_file根据键构造数组image.
所以现在问题是为什么是$_FILES['image']['tmp_name']空的?
我'error'通过暂时将异常更改为来检查字段
throw new Exception('File was not uploaded. ' . $this->_file['error'], $code);
Run Code Online (Sandbox Code Playgroud)
我知道7,这Failed to write file to disk.意味着这是一个权限问题.执行a phpinfo()检查upload_tmp_dir设置的位置并确保其可写.
在我的情况下,我在/tmp目录中没有文件空间.
您报告的确切异常/错误消息不会以字符串形式显示在 Magento 的源代码中,因此我不能 100% 确定我在这里为您指明了正确的方向。
也就是说,magento 中的大多数上传都是由save该类的实例化对象上的方法处理的Varien_File_Uploader。
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;
}
}
Run Code Online (Sandbox Code Playgroud)
在这个函数中扔一些调试语句来看看是否
这是被调用的那个,但失败了
找出为什么它可能返回 false(即不上传文件)