0

我正在使用 Codeigniter 2.1.3,我在 /home 文件夹中有网站外部的图像,无法显示图像。

 <img src="<?php echo img('/home/pedro/iagora.jpg');?>" title="" alt="avatar_<?php echo $project['id']; ?>" width="120" height="80"/>

我努力了:

     <img src="<?php echo '/home/pedro/iagora.jpg';?>" title="" alt="avatar_<?php echo $project['id']; ?>" width="120" height="80"/>

和:

     <img src="/home/pedro/iagora.jpg" title="" alt="avatar_<?php echo $project['id']; ?>" width="120" height="80"/>

但这些都不起作用。

4

3 回答 3

0

I suggest you to create the folder "assets" in your base folder. In "assets" you will store js, css, uploads images and all others. In this form you can organize better your aplication

And after that, you can load the images with base_url(). for example:

<img src="<?php echo base_url(); ?>assets/your_folder/your_image.jpg" title="" alt="avatar_<?php echo $project['id']; ?>" width="120" height="80" />
于 2013-02-21T08:14:55.513 回答
0

i saved the script file on the root of the website and now its working

<img src="<?php echo base_url().'get_image.php?i='.$images_thumb_dir.$project['avatar'];?>" title="" alt="avatar_<?php echo $project['id']; ?>" width="120" height="80"/>

thanks Pedro

于 2013-02-21T10:54:34.010 回答
0

如果这些文件位于 Web 根目录之外,则您无法正常通过 HTTP 访问它们。您需要编写一个 PHP 脚本来为您输出图像:

<img src="/get_image.php?i=iagora.jpg" title="">

/get_image.php将是检索图像并为您输出的 PHP 文件。该i参数将是您想要的图像的名称。

该文件看起来像:

<?php
    $file_name = $_GET['i'];
    $file = '/home/pedro/' . $file_name;

    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename=' . basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    exit;
?>
于 2013-02-20T20:41:18.177 回答