【发布时间】:2014-07-27 00:38:46
【问题描述】:
我是编程新手,现在正在学习 php。我已经安装了 xamp 并编写了一些代码。我的外部高清上有一些图像,我想展示一些图片。 问题是我可以使用以下代码获取图像路径列表:
echo "<html><body>";
$outerDir = "x:\map\maps\more\\";
$total = count (array_diff (scandir ($outerDir), Array (".", "..")));
$dirs = array_diff( scandir( $outerDir ), Array( ".", ".." ) );
foreach ($dirs as $d) {
if (!is_dir($outerDir . $d)) {
echo $d . "<br>";
}
}
但如果我想将其显示为图像,则无法显示图像。我在 foreach 中试过这个:
if (!is_dir($outerDir . $d)) {
$file = $outerhDir . $d;
echo 'img src="' . $outerDir . $d . '> <br>';
echo "<img src='" . $outerDir . '\\' . $d . "'alt='" . $d . "'> <br>";
}
但它们都不起作用。我还尝试了这样的 header 和 file_get_content:
if (!is_dir($outerDir . $d)) {
$file = $outerDir . $d;
header('Content-type: image/jpeg');
header('Content-Length:' . filesize($file));
$image = file_get_contents('$file');
echo $image . "<br>";
}
即使是简单的 html 代码也行不通!像这样:
echo '<img src="x:\map\maps\more\needwonder.jpg"> <br>';
对接!!当我将其中一张图像存储在与我的 php 文件相同的文件夹中时,它将起作用!像这样:
echo '<img src="needwonder.jpg"> <br>';
但出于安全、技术和舒适的原因,我不想将所有文件与 php 文件放在同一个文件夹中,并且我想学习编程而不是避免代码出现问题或问题。
所以我希望我很好地定义了我的问题,并希望你们中的一个人和/或女孩知道解决方案来帮助我
【问题讨论】:
标签: php arrays image file-get-contents hard-drive