Magento 1.9.2和php7-图片上传错误


9

我只是在用Php 7测试Magento 1.9.2。所有功能似乎都可以使用,但是突然间,我尝试上传该产品的图片。我收到如下错误:

Fatal error</b>:  Uncaught Error: Function name must be a string in /home/admin/domains/store.com/public_html/dev/lib/Varien/File/Uploader.php:259
Stack trace:
#0 /home/admin/domains/store.com/public_html/dev/lib/Varien/File/Uploader.php(180): Varien_File_Uploader-&gt;_validateFile()
#1 /home/admin/domains/store.com/public_html/dev/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/GalleryController.php(46): Varien_File_Uploader-&gt;save('/home/admin/dom...')
#2 /home/admin/domains/store.com/public_html/dev/app/code/core/Mage/Core/Controller/Varien/Action.php(418): Mage_Adminhtml_Catalog_Product_GalleryController-&gt;uploadAction()
#3 /home/admin/domains/store.com/public_html/dev/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(254): Mage_Core_Controller_Varien_Action-&gt;dispatch('upload')
#4 /home/admin/domains/store.com/public_html/dev/app/code/core/Mage/Core/Controller/Varien/Front.php(172): Mage_Core_Controller_Varien_Router_Standard-&gt;match(Object(Mage_Core_Controller in <b>/home/admin/domains/store.com/public_html/dev/lib/Varien/File/Uploader.php

有人知道如何解决吗?

在259行左右的upload.php中影响的函数

protected function _validateFile()
    {
        if ($this->_fileExists === false) {
            return;
        }

        //is file extension allowed
        if (!$this->checkAllowedExtension($this->getFileExtension())) {
            throw new Exception('Disallowed file type.');
        }
        //run validate callbacks
        foreach ($this->_validateCallbacks as $params) {
            if (is_object($params['object']) && method_exists($params['object'], $params['method'])) {
                $params['object']->$params['method']($this->_file['tmp_name']);
            }
        }
    }

Answers:


34

http://php.net/manual/de/migration70.incompatible.php https://wiki.php.net/rfc/uniform_variable_syntax

由于采用统一的变量语法,因此现在严格从左到右解释该代码。

线

$params['object']->$params['method']($this->_file['tmp_name']);

应该

$params['object']->{$params['method']}($this->_file['tmp_name']);

您可以在此答案中找到要编辑的所有文件的概述。


很酷,可以100%工作,我希望Magento 1.9.2没有任何其他php 7不兼容。感谢帮助!
sellio 2015年

此代码对我有用magento 1.9.2.4
matinict '16

此解决方案包含您需要编辑才能获得良好PHP7性能的所有文件:magento.stackexchange.com/a/105604/37536
Alex Timmer

太棒了...对我来说效果很好
Ramesh Kumar

2

除了上述答案外,别忘了检查文件:

第259行的\ includes \ src \ Varien_File_Uploader.php

更换

$params['object']->$params['method']($this->_file['tmp_name']);

$params['object']->{$params['method']}($this->_file['tmp_name']);

只是重新编译而不是编辑这些临时文件?
安迪
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.