Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.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
显示来自php的图像_Php_Html_Image - Fatal编程技术网

显示来自php的图像

显示来自php的图像,php,html,image,Php,Html,Image,我正在尝试在html文件中显示图像。到目前为止,我使用了一个url:,它工作得很好,现在当我尝试用数据库中的图像替换它时,它不会显示任何内容。图像路径是:D:/uwamp/www/project/upload/tcf_animal17.jpg我尝试了不同的路径,但不起作用。我不确定问题出在哪里。我打印了数据,这是一条好路 html 视图: public function generate($data) { $contenu = $this->generateFile($this-

我正在尝试在html文件中显示图像。到目前为止,我使用了一个url:,它工作得很好,现在当我尝试用数据库中的图像替换它时,它不会显示任何内容。图像路径是:D:/uwamp/www/project/upload/tcf_animal17.jpg我尝试了不同的路径,但不起作用。我不确定问题出在哪里。我打印了数据,这是一条好路

html

视图:

public function generate($data) 
{
    $contenu = $this->generateFile($this->viewFile, $data);
    $racineWeb = Configuration::get("racineWeb", "/");
    $view = $this->generateFile('View/Template/index.php',
            array('title' => $this->viewTitle, 'contenu' => $contenu,
                'racineWeb' => $racineWeb));
    echo $view;
}

private function generateFile($viewFile, $data) 
{
    if (file_exists($viewFile)) 
    {
        extract($data);
        ob_start();
        require $viewFile;
        return ob_get_clean();
    }
    else 
    {
        throw new Exception("can't find '$viewFile'");
    }
}

您的问题是,数据库中图像的路径存储为您计算机的本地路径(
D:/uwamp/www/project/upload/tcf_animal17.jpg
),要正确显示,它需要是相对于web服务器文档根的路径

例如,如果web服务器文档根为
D:/uamp/www
,则需要存储的图像路径应为
project/upload/tcf_animal17.jpg

当然,如果您无法将图像存储在web根目录中,那么您始终可以选择直接转储内容,但出于性能原因,这并不是一个好主意:

<?php
    $mime = image_type_to_mime_type(exif_imagetype(string $image_path));
    $data = "data:$mime;base64," . base64_encode(file_get_contents($image_path)); ?>
?>
<img src="<?= $data ?>">

?>
">

此代码非常粗糙,没有错误检查-您需要为生产级应用程序添加此代码。

您的问题是,数据库中图像的路径存储为您机器的本地路径(
D:/uwamp/www/project/upload/tcf_animal17.jpg
),其中要正确显示,它需要是相对于web服务器文档根的路径

例如,如果web服务器文档根为
D:/uamp/www
,则需要存储的图像路径应为
project/upload/tcf_animal17.jpg

当然,如果您无法将图像存储在web根目录中,那么您始终可以选择直接转储内容,但出于性能原因,这并不是一个好主意:

<?php
    $mime = image_type_to_mime_type(exif_imagetype(string $image_path));
    $data = "data:$mime;base64," . base64_encode(file_get_contents($image_path)); ?>
?>
<img src="<?= $data ?>">

?>
">

此代码非常粗糙,没有错误检查-您需要为生产级应用程序添加此代码。

您的问题是,数据库中图像的路径存储为您机器的本地路径(
D:/uwamp/www/project/upload/tcf_animal17.jpg
),如果要正确显示,它需要是相对于web服务器文档根的路径

例如,如果web服务器文档根为
D:/uamp/www
,则需要存储的图像路径应为
project/upload/tcf_animal17.jpg

当然,如果您无法将图像存储在web根目录中,那么您始终可以选择直接转储内容,但出于性能原因,这并不是一个好主意:

<?php
    $mime = image_type_to_mime_type(exif_imagetype(string $image_path));
    $data = "data:$mime;base64," . base64_encode(file_get_contents($image_path)); ?>
?>
<img src="<?= $data ?>">

?>
">

此代码非常粗糙,没有错误检查-您需要为生产级应用程序添加此代码。

您的问题是,数据库中图像的路径存储为您机器的本地路径(
D:/uwamp/www/project/upload/tcf_animal17.jpg
),其中要正确显示,它需要是相对于web服务器文档根的路径

例如,如果web服务器文档根为
D:/uamp/www
,则需要存储的图像路径应为
project/upload/tcf_animal17.jpg

当然,如果您无法将图像存储在web根目录中,那么您始终可以选择直接转储内容,但出于性能原因,这并不是一个好主意:

<?php
    $mime = image_type_to_mime_type(exif_imagetype(string $image_path));
    $data = "data:$mime;base64," . base64_encode(file_get_contents($image_path)); ?>
?>
<img src="<?= $data ?>">

?>
">

此代码非常粗糙,没有错误检查-您需要为生产级应用程序添加此代码。

例如,尝试使用映像的完整路径。例如,尝试使用映像的完整路径。例如,尝试使用映像的完整路径。例如,尝试使用映像的完整路径。例如,尝试使用映像的完整路径。