简体   繁体   English

PHP / html / mysql图像显示

[英]PHP/html/mysql Image display

Hey my php/mysql/html people, 嘿,我的php / mysql / html人,

I have this variable that holds a path to an image and then insert it into a db (yes, I am using mysql_real_escape_string) which works perfectly. 我有一个变量,它保存着图像的路径,然后将其插入到数据库中(是的,我正在使用mysql_real_escape_string),它可以完美运行。

$file_name = $_FILES["file"]["name"];
$path='images\ '. $file_name;
insert into...blah blah blah

The path is later pulled from the db and stored in said variable. 路径随后从数据库中拉出并存储在所述变量中。

$path       = $row['file_path'];

I am trying to display it with: 我正在尝试将其显示为:

 // the contents of $path in this case is: images\ cats.jpg
echo "<img src=" . $path . ">";

However the image breaks because the only thing that src pics up is: images\\ and not the actualname+extension of the image. 但是,图像损坏了,因为src唯一显示的是:images \\而不是图像的实际名称和扩展名。 I know this probably has to do with the slashes, but I am a newbie and could use some help. 我知道这可能与斜杠有关,但是我是新手,可以使用一些帮助。 Thanks in advance! 提前致谢!

your 你的

$path='images\ '. $file_name; 

should be 应该

$path='images\'. $file_name;

Print $path variable & see the values. 打印$ path变量并查看值。

echo $path;exit;

You will get value on web browser. 您将在网络浏览器上获得价值。

Copy the value displayed on browser & paste it in the URL, if you see the image, your saved path is correct, if not, you have gone wrong in specifying the relative path too the resource. 复制浏览器上显示的值并将其粘贴到URL中,如果您看到图像,则保存的路径正确,否则,在指定相对路径和资源时也出错了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM