php 打开目录错误;没有找到这样的文件或目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9155992/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Opendir error; No such file or directory found
提问by stevieD
This may be a very easy question. I am working in directory /mobile and I have photos in a directory /uploads.
这可能是一个非常简单的问题。我在目录/mobile 中工作,我在目录/uploads 中有照片。
I am getting the error:
我收到错误:
Warning: opendir(http://www.yoozpaper.com/uploads) [function.opendir]: failed to open dir: not implemented in /hermes/bosweb/web088/b881/ipg.yoozpapercom/mobile/sportspage.php on line 313
Warning: opendir(http://www.yoozpaper.com/uploads) [function.opendir]: failed to open dir: not implemented in /hermes/bosweb/web088/b881/ipg.yoozpapercom/mobile/sportspage.php on line 313
I am putting this into a variable $dir = "http://www.yoozpaper.com/uploads"
我把它放到一个变量 $dir = "http://www.yoozpaper.com/uploads"
for the image src=$dir/$file
.
对于图像src=$dir/$file
。
Note that this is working when I am working with files in the main directory.
请注意,当我处理主目录中的文件时,这是有效的。
Any help on this would be greatly appreciated.
对此的任何帮助将不胜感激。
Code below:
代码如下:
$dir = "http://www.yoozpaper.com/uploads";
//open directory
//打开目录
if ($opendir = opendir($dir))
{
//read directory
//读取目录
while (($file = readdir($opendir)) !==FALSE)
{
if ($file==$imagename)
//can specify height and width below
//可以在下面指定高度和宽度
echo "<img width='75%' height='30%' src='$dir/$file' title='$headline - Yoozpaper News Online' alt='$headline'><br /><br />";
回答by Your Common Sense
You have to understand the difference between a filesystemand an HTTP daemon.
Although they have somewhat similar appearance, it is absolutely different matters.
您必须了解文件系统和HTTP 守护程序之间的区别。
虽然他们的外表有些相似,但这是完全不同的事情。
To use opendir, you have to open *a directory, not HTTP resource.
要使用 opendir,您必须打开一个目录,而不是 HTTP 资源。
opendir('../uploads');
should work
应该管用
opendir($_SERVER['DOCUMENT_ROOT'].'/uploads');
would be better as it will always point to the uploads directory, no matter from where you called it.
会更好,因为它始终指向上传目录,无论您从何处调用它。
回答by SoWhat
http://www.yoozpaper.com/uploadsus a URL not a directory. You can't access it using opendir. You need the system path to it for example "/home/user/public_html/uploads" or something. Get the path to the directory using your file manager or control panel
http://www.yoozpaper.com/uploads我们是一个 URL 而不是目录。您无法使用 opendir 访问它。您需要系统路径,例如“/home/user/public_html/uploads”或其他内容。使用文件管理器或控制面板获取目录路径
It might "/hermes/bosweb/web088/b881/" in your case. m not sure though. In any case, get the local path
在您的情况下,它可能是“/hermes/bosweb/web088/b881/”。我不确定。无论如何,获取本地路径