我已将图像上传到文件夹中,并将路径存储到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.