微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

$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.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐