我在使用 OpenDir 时遇到 URL 文件访问错误。为什么?
<?php
$pathname = "http://myserver.com/projects/" . $_GET['project'] . "/";
if ($handle = opendir($pathname)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && (strpos($file, '.jpg',1)) ) {
$photo= $pathname . $file;
echo "<image src=\"" . $file . "\">";
}
}
closedir($handle);
}
?>
有我的代码。我想做的就是传递一个 URL 参数,如“project=Flowers”,然后让 PHP 打开一个名为 /flowers/ 的文件夹,并返回其中的所有 .jpg 图像。
但是,当我运行代码时,出现以下错误:
**警告:opendir() [function.opendir]:URL 文件访问已禁用 在服务器配置中 /nfs/c01/h03/mnt/73283/domains/myserver.com/test.php 上 第 3 行
警告:opendir(http://myserver.com/projects/flowers/) [function.opendir]:无法打开目录:没有合适的包装器 发现于 /nfs/c05/h02/mnt/76383/domains/kulthouse.com/html/staging/work.php 上 第 3 行**
有什么想法为什么这行不通吗?
<?php
$pathname = "http://myserver.com/projects/" . $_GET['project'] . "/";
if ($handle = opendir($pathname)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && (strpos($file, '.jpg',1)) ) {
$photo= $pathname . $file;
echo "<image src=\"" . $file . "\">";
}
}
closedir($handle);
}
?>
There is my code. All I'm trying to do is pass a URL parameter like "project=Flowers", and have PHP open a folder called /flowers/ and return ALL of the .jpg images inside it.
However, when I run my code, I get these errors:
**Warning: opendir() [function.opendir]: URL file-access is disabled
in the server configuration in
/nfs/c01/h03/mnt/73283/domains/myserver.com/test.php on
line 3Warning: opendir(http://myserver.com/projects/flowers/)
[function.opendir]: failed to open dir: no suitable wrapper could be
found in
/nfs/c05/h02/mnt/76383/domains/kulthouse.com/html/staging/work.php on
line 3**
Any ideas why this won't work??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为你正在使用文件系统函数来访问网络URL
所以,我会让它的
basename()在这里非常重要,不要让任何人浏览你的任何目录磁盘
Because you're using filesystem function to access a web URL
So, I'd make it
basename() is very important here, not letting anyone to browse any directory on your disk