用 php 回显图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14182823/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Echo image with php
提问by user1919
I am trying to do something really simple with php but I can not find where I have the mistake! So, I want to echo an image like this (part of the code):
我正在尝试用 php 做一些非常简单的事情,但我找不到我出错的地方!所以,我想回显这样的图像(代码的一部分):
$file_path[0] = "/Applications/MAMP/htdocs/php_test/image_archive/".$last_file[0];
echo $file_path[0];
echo "<br>";
echo "<img src=\".$file_path[0].\" alt=\"error\">";
I must have some kind of error when I echo the img tag but I can not find it. Any help would be appreciated.
当我回显 img 标签但我找不到它时,我一定有某种错误。任何帮助,将不胜感激。
<div class="content">
<h1> Map</h1>
<?php
include '/Applications/MAMP/htdocs/php_test/web_application_functions/last_file.php';
$last_file = last_file();
$file_path[0] = "/Applications/MAMP/htdocs/php_test/image_archive/".$last_file[0];
echo $file_path[0];
echo "<br>";
echo '<img src="' . $file_path[0] . '" alt="error">';
?>
<!-- end .content --></div>
回答by PassKit
You should use a path either relative to the server root, or the current file.
您应该使用相对于服务器根目录或当前文件的路径。
echo "<img src='/php_test/image_archive/" . $last_file[0] . "' alt='error'>";
回答by Popnoodles
echo "<img src=\".$file_path[0].\" alt=\"error\">";
is wrong
是错的
echo "<img src=\"".$file_path[0]."\" alt=\"error\">";
is what you think you're doing
是你认为你在做什么
It's useful to use single quotes so you don't make this mistake
使用单引号很有用,这样你就不会犯这个错误
echo '<img src="' . $file_path[0] . '" alt="error">';
Secondly
其次
/Applications/MAMP/htdocs/php_test/image_archive/looks like a path not a directory
/Applications/MAMP/htdocs/php_test/image_archive/看起来像路径而不是目录
Perhaps you mean
也许你的意思是
$file_path[0] = "/php_test/image_archive/".$last_file[0];
or
或者
$file_path[0] = "image_archive/".$last_file[0];

