2

我正在尝试以编程方式添加可下载产品的链接,下面是我正在处理的代码。

$linkfile = array();
$_highfilePath = $FolderPath.DS.$fname;
$linkfile[] = array(
        'file' => $filePath,
        'name' => $fname,
        'size' => filesize($filePath),
        'status' => 'new'
);

$linkFileName = Mage::helper('downloadable/file')->moveFileFromTmp(
            Mage_Downloadable_Model_Link::getBaseTmpPath(),
            Mage_Downloadable_Model_Link::getBasePath(),
            $linkfile
    );

    $linkModel = Mage::getModel('downloadable/link')->setData(array(
            'product_id' => $product->getId(),
            'sort_order' => 0,
            'number_of_downloads' => 0, // Unlimited downloads
            'is_shareable' => 2, // Not shareable
            'link_url' => '',
            'link_type' => 'file',
            'link_file' => json_encode($linkfile),
            'sample_url' => $SamplePathUrl,
            'sample_file' => json_encode($linkfile),
            'sample_type' => 'file',
            'use_default_title' => true,
            'default_price' => 0,
            'price' => 0,
            'store_id' => 0,
            'website_id' => $product->getStore()->getWebsiteId(),
    ));

这是我得到的错误An error occurred while saving the file(s).。请帮忙

4

1 回答 1

0

如果没有更多信息,就无法确定诊断。这是失败的调用的代码:

/**
 * Checking file for moving and move it
 *
 * @param string $baseTmpPath
 * @param string $basePath
 * @param array $file
 * @return string
 */
public function moveFileFromTmp($baseTmpPath, $basePath, $file)
{
    if (isset($file[0])) {
        $fileName = $file[0]['file'];
        if ($file[0]['status'] == 'new') {
            try {
                $fileName = $this->_moveFileFromTmp(
                    $baseTmpPath, $basePath, $file[0]['file']
                );
            } catch (Exception $e) {
                Mage::throwException(Mage::helper('downloadable')->__('An error occurred while saving the file(s).'));
            }
        }
        return $fileName;
    }
    return '';
}

一个好的起点是检查文件系统权限,确保您的数据类型与函数注释中指定的类型匹配,并确保所有文件和目录都存在。

于 2014-11-21T01:58:25.650 回答