2016-03-22 104 views
2

我想从主题目录中的文件中获取缩略图,但getThumbnail()函数需要我传递一个文件对象。如何从Concrete5中的文件路径获取文件对象?

这显然是行不通的:

$v = View::getInstance(); 
$themePath = $v->getThemePath();  
$thumbnail = $imageHelper->getThumbnail($themePath.'/images/abc.jpg', 100, 100, true); 

那么,这可以从文件路径获取文件对象?

+0

难道我的回答您解决问题? –

回答

1

如果该文件只存在于文件夹结构,但并不像concrete5文件对象,你需要的FileImporter第一:

use Concrete\Core\File\Importer; 
$fi = new Importer(); 
if($fv = $fi->importIncomingFile($themePath . '/' . $filename)){ 
    $returnFile = \Concrete\Core\File\File::getByID($fv->getFileID()); 
} 

然后你可以将那个文件对象的getThumbNail()功能。该getThumbNail()不走的路径,但图像对象作为第一个参数:

$imageHelper = Core::make('helper/image');  
$thumbnail = $imageHelper->getThumbnail($returnFile, 300, 9999, false); 

下面是采取(从API)所有PARAMS:

/** 
* Returns a path to the specified item, resized and/or cropped to meet max width and height. $obj can either be 
* a string (path) or a file object. 
* Returns an object with the following properties: src, width, height 
* @param mixed $obj 
* @param int $maxWidth 
* @param int $maxHeight 
* @param bool $crop 
*/ 
public function getThumbnail($obj, $maxWidth, $maxHeight, $crop = false) 
+0

我现在在不同的上下文中使用它,我试图删除这个文件,但它不是这样工作的:'$ returnFile-> delete();'。这不应该工作吗? – user1448031

+0

它应该......你得到什么错误? –

+0

我没有收到任何错误。这正是我想要做的: if($ fv = $ fi-> import('application/files/test.pdf')){return 0File = \ Concrete \ Core \ File \ File :: getByID($ fv-> getFileID()); } $ mh-> addAttachment($ returnFile); \t \t \t \t $ returnFile-> delete(); – user1448031