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.

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...