我想通过c:/user_name/image/image_name.jpg使用加载图像http://intranet/user/index.php.
<img src="file:///c:/user_name/image/image_name.jpg">
Run Code Online (Sandbox Code Playgroud)
我该如何显示它们?
谢谢让
您意识到只有当该图像位于将要查看此页面的每台计算机上的完全相同的位置时,这才会起作用吗?有没有理由通过网络服务器本身无法正常提供图像?
由于你使用的是绝对的Windows路径,这只适用于Windows机器,它实际上有一个C驱动器,相同的目录等等......它在Mac或Linux或其他任何方框都不起作用,因为他们不打扰驱动器号.
跟进:
在稍微思考一下你的问题之后,看起来你想要提供一个未存储在你的文档根目录中并从特定页面提供服务的特定图像.如果你在index.php的开头放了这样的东西:
<?php
if (isset($_GET['username']) && isset($_GET['image'])) {
$user = $_GET['username'];
$image = $_GET['image'];
$path = "C:\\{$user}\\image\\{$image}";
if (is_readable($path)) {
$info = getimagesize($path);
if ($info !== FALSE) {
header("Content-type: {$info['mime']}");
readfile($path);
exit();
}
}
}
?>
Run Code Online (Sandbox Code Playgroud)
在HTML中:
<img src="index.php?user=user_name&image=image_name" />
Run Code Online (Sandbox Code Playgroud)
当然,这是非常基本的,以这种方式提供文件是非常不安全的,但很可能这是你想要的基础知识.