gpt4 book ai didi

php - 从存储在mysql中的路径显示图像

转载 作者:可可西里 更新时间:2023-11-01 08:04:20 25 4
gpt4 key购买 nike

我已将图片上传到文件夹中,并将路径存储到 MySQL 数据库中。路径已保存,图片已成功插入文件夹。但我的问题是当我从存储在数据库中的路径显示图像时。它没有显示。当我回显图像路径时,它会显示图像路径。我检查了我的浏览器设置,一切正常。这是我的代码。请任何人帮助。

$up=move_uploaded_file($_FILES['profile']['tmp_name'],dirname($_SERVER['DOCUMENT_ROOT']).'/htdocs/upload/image/'.$name);
$path = dirname($_SERVER['DOCUMENT_ROOT']).'/htdocs/upload/image/';
$location = $path . $_FILES['profile']['name'];
$ins=mysqli_query($con, "INSERT into image (url) values ('$location')");
echo 'image uploaded and stored';
echo "$location"; //It displays D:/xampp/htdocs/upload/image/Chrysanthemum.jpg
echo '<img width="250" height="250" src= "'.$location.'"/>';//It doesn't display anything.

最佳答案

试试这个:

尽量使用相对路径而不是绝对路径。相对路径可帮助您从任何服务器、任何目录运行脚本。

$path = 'upload/image/';
$location = $path . $_FILES['profile']['name'];

move_uploaded_file($_FILES['profile']['tmp_name'], $location);

$ins = mysqli_query($con, "INSERT into image (url) values ('$location')");
echo 'image uploaded and stored';
echo '<img width="250" height="250" src= "'.$location.'"/>';

Note: you need to have a folder name upload/image in the same directory from where the script run. As your requirement, you want to show image from mysql, but did't do it, for that you need to query the table again.

关于php - 从存储在mysql中的路径显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36995820/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com