使用cakephp3从上传后的数据库中检索图像


Retrieving images from database after uploaded using cakephp3

使用Cake''ORM''TableRegistry;

$websites=>TableRegistry::get("网站");

$query=>$websites->find()->order(['creation_date'=>'DESC']);

  echo "<table>";
    echo"<tr>
           <td>Cover Image</td>
           <td>Company Name</td>
           <td>Date Added</td> 
         </tr>";
    foreach ($query as $row) {
    echo"<tr>
          <td>".$row['Website']['image']."</td>
          <td>".$row->company."</td
          <td>".$row->creation_date."</td>            </tr>";
    }      
 echo"</table>";
?>      
      I remember this code in cakephp2 and display the images path "app/webroot/img/websites/"
    <?php echo $this->Html->image('websites/' . $row['Website']['image']);

但是如何在cakeph3中做到这一点,以显示图像。?>

您似乎不知道自己的真正问题。你的问题似乎是有人在为上传图像的正确HTML代码而苦苦挣扎。为此,您只需要给数据库表列中的上传字段一个varchar类型,然后在将图像从文件类型上传到该字段的视图中。类似于:

<div class="form-group">
       <?php
            echo $this->Form->input('your_column_name', [ 'type' => 'file']); 
        ?>
</Div>

但是,如果您的问题是无法检索或发送到index.ctp或前端视图上传的图像,那么您的解决方案如下:如何在cakeph3.7中检索通过带有blob列的表单上传到mysql数据库中的图像的字符串名称?

在cakehp3中没有任何大的区别,它很简单,就像下面的代码

 <?php foreach ($websites as $websites): ?>
    <?= $this->Html->image('websites/'.$websites->image) ?> 
 <?php endforeach; ?>