Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Contao 3.5和Imagick php扩展_Php_Imagick_Php Extension_Contao - Fatal编程技术网

Contao 3.5和Imagick php扩展

Contao 3.5和Imagick php扩展,php,imagick,php-extension,contao,Php,Imagick,Php Extension,Contao,我试图使用php扩展名“Imagick”从PDF文件创建JPG图像。 我使用Contao 3.5.14 有两种情况需要此扩展才能工作: 第一种情况是将PDF文件附加到新闻文章中。 在本例中,我只是创建了一个自定义新闻列表模块,并为其分配了一个自定义模板。 在这个自定义模板中,我只是抛出一些php来保存我的JPG。 它确实工作得很好: <div class="publication layout_full block<?= $this->class ?>"> &l

我试图使用php扩展名“Imagick”从PDF文件创建JPG图像。
我使用Contao 3.5.14

有两种情况需要此扩展才能工作:
第一种情况是将PDF文件附加到新闻文章中。
在本例中,我只是创建了一个自定义新闻列表模块,并为其分配了一个自定义模板。
在这个自定义模板中,我只是抛出一些php来保存我的JPG。
它确实工作得很好:

<div class="publication layout_full block<?= $this->class ?>">
  <h2><?= $this->headline ?></h2>
  <?php if ($this->hasMetaFields): ?>
    <p class="info"><?php echo $this->parseDate("F Y", strtotime($this->date)); ?><?= $this->author ?> <?= $this->commentCount ?></p>
  <?php endif; ?>
  <?php if ($this->hasSubHeadline): ?>
    <h4><?= $this->subHeadline ?></h4>
  <?php endif; ?>

  <?php if ($this->addImage): ?>
  <div class='image_container'>
    <img src='<?= $this->singleSRC ?>'/>
</div>
    <?php endif; ?>

  <?php if ($this->enclosure): ?>
    <div class="enclosure">
      <?php for($i=0;$i<count($this->enclosure);$i++) { 

  // the IMAGICK bit:

$pdf_file = $this->enclosure[$i]['enclosure'].'[0]';
$save_to = 'files/thumbnails/'.$this->enclosure[$i]['link'].'.jpg';
if (!file_exists($save_to)) {
$im = new Imagick($pdf_file);
$im->setImageFormat ("jpeg");
$im->writeImage ($save_to);
}
?>
        <div class="vignette"><a target="_blank" href="<?= $this->enclosure[$i]['enclosure'] ?>" title="<?= $this->enclosure[$i]['title'] ?> (<?= $this->enclosure[$i]['filesize'] ?>)"><img src='<?= $save_to ?>'/></a></div>

     <?php } ?>

    </div>
  <?php endif; ?>

// and so on...

</div> 
ce_download.html5的第11行是 $im=新的Imagick($pdf\u文件)
我最初认为这是一个与路径相关的问题,但这并不是因为JPG被正确创建并且在前端显示良好。 所以我想这一定与ce模板的工作方式以及它们在后台的显示方式有关。
我真的不知道如何让这个php代码在不干扰ce_下载模板的情况下工作

我非常感谢任何能帮助我的人。
问候

Vinny

您应该通过
TL\u根
常量使用绝对路径。e、 g:

$pdf\u file=TL\u ROOT.'/'$此->singleSRC.[0];
$save_to=TL_ROOT'/文件/缩略图/'.$this->id..jpg';
如果(!file_存在($save_to)){
$im=新的Imagick($pdf\u文件);
$im->setImageFormat(“jpeg”);
$im->writeImage($save\u to);
}

Try
newimagick(TL_ROOT./.$pdf文件)@FritzmgWaouh!它现在真的起作用了。。。所以这是一个路径问题:-/请随意更改您的评论作为答案,这样我就可以选择它作为答案。非常感谢。。。
<?php $this->extend('block_searchable'); ?>
  <?php $this->block('content'); ?>
<!--------Here's the IMAGICK bit------------->
<?php
$pdf_file = $this->singleSRC.'[0]';
$save_to = 'files/thumbnails/'.$this->id.'.jpg';
if (!file_exists($save_to)) {
    $im = new Imagick($pdf_file);
    $im->setImageFormat ("jpeg");
    $im->writeImage ($save_to);
    }
?>
<!--------Here's end the IMAGICK bit------------>
<a href="<?= $this->href ?>" title="<?= $this->title ?>">
        <div class="image_container">
          <img style="width:100%;height:auto" src='<?= $save_to ?>' />
        </div>
      </a>
      <div class="teaser">
        <a href="<?= $this->href ?>" title="<?= $this->title ?>">
            <h2> <?= $this->link ?> </h2>
        </a>
      </div>

      <?php $this->endblock(); ?>
Fatal error: Uncaught exception ImagickException with message unable to open image `files/Folder/myFile.pdf': No such file or directory @ error/blob.c/OpenBlob/2589 thrown in templates/ce_download.html5 on line 11
#0 templates/ce_download.html5(11): Imagick->__construct('files/Folder...')
#1 system/modules/core/library/Contao/BaseTemplate.php(88): include('/home/www/clien...')
#2 system/modules/core/library/Contao/Template.php(277): Contao\BaseTemplate->parse()
#3 system/modules/core/classes/FrontendTemplate.php(46): Contao\Template->parse()
#4 system/modules/core/elements/ContentElement.php(289): Contao\FrontendTemplate->parse()
#5 system/modules/core/elements/ContentDownload.php(72): Contao\ContentElement->generate()
#6 system/modules/core/library/Contao/Controller.php(484): Contao\ContentDownload->generate()
#7 system/cache/dca/tl_content.php(1166): Contao\Controller::getContentElement(Object(Contao\ContentModel))
#8 system/modules/core/drivers/DC_Table.php(4321): tl_content->addCteType(Array)
#9 system/modules/core/drivers/DC_Table.php(378): Contao\DC_Table->parentView()
#10 system/modules/core/classes/Backend.php(650): Contao\DC_Table->showAll()
#11 system/modules/core/controllers/BackendMain.php(131): Contao\Backend->getBackendModule('article')
#12 contao/main.php(20): Contao\BackendMain->run()
#13 {main}