题
好的,我有一个烦人的问题。我在自定义辅助模块中有一些代码,用于调整图像大小并保存缓存的副本。现在这不起作用。但是,如果我进入mage.php并更改声明的变量 DS
从 DIRECTORY_SEPARATOR
至 /
它可以很好地工作。但是,一些使用标准的社区模块中断 DS
.
这是我的方法:
public function resizeImg($fileName, $width, $height, $constrain = false, $ratio = false)
{
$folderURL = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
$imageURL = $folderURL . $fileName;
$basePath = Mage::getBaseDir(Mage_Core_Model_Store::URL_TYPE_MEDIA) . DS . $fileName;
$newPath = Mage::getBaseDir(Mage_Core_Model_Store::URL_TYPE_MEDIA) . DS . "resized" . DS . $width . DS . $fileName;
//if width empty then return original size image's URL
if ($width != '') {
//if image has already resized then just return URL
if (file_exists($basePath) && is_file($basePath)/* && !file_exists($newPath)*/) {
$imageObj = new Varien_Image($basePath);
$imageObj->constrainOnly($constrain);
$imageObj->keepAspectRatio($ratio);
$imageObj->keepFrame(FALSE);
$imageObj->resize($width, $height);
$imageObj->save($newPath);
}
$resizedURL = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . "resized" . DS . $width . DS . $fileName;
} else {
$resizedURL = $imageURL;
}
return $resizedURL;
}
和工作应用程序/mage.php
define('DS', DIRECTORY_SEPARATOR);
现在,如果我将DS更改为'/',则可以正常工作。
然后,我尝试了以下内容:
define('DS2', '/');
然后将DS更改为我的方法中的DS2,但这也不起作用,也不将其更改为字符串或变量。
从我的搜索中,目录选择器是由服务器类型定义的,这应该是Linux服务器,但只有当我自己使用DS时,它会破裂并尝试输出而不是 /,其他任何地方都正确输出 /。
我做错了吗?
解决方案
您将URL与目录混淆。
getBaseUrl
是用于URL,它将始终由 /
getBaseDir
用于目录,它将具有变量 DS
由PHP的常数变量定义 DIRECTORY_SEPARATOR
- Magento缩短了什么 DS