duanliang1019 2016-05-03 04:49
浏览 77
已采纳

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

I have uploaded the image into the folder and stored the path into the MySQL Database. The path has been stored and the image has been inserted into the folder successfully. But my problem is when i display the image from the path which is stored in db. It is not displaying. When i echo the image path, it displays the image path. I checked my browser settings, it's all ok. Here is my code. Please anybody help.

$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.
  • 写回答

2条回答 默认 最新

  • dsd119120 2016-05-03 04:57
    关注

    Try this:

    Try to use relative path not absolute path. The relative path helps you to run the script from any server, any directory.

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示