Opendir error; No such file or directory found

stevieD picture stevieD · Feb 6, 2012 · Viewed 21.5k times · Source

This may be a very easy question. I am working in directory /mobile and I have photos in a directory /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

I am putting this into a variable $dir = "http://www.yoozpaper.com/uploads"

for the image 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 />";

Answer

Your Common Sense picture Your Common Sense · Feb 6, 2012

You have to understand the difference between a filesystem and an HTTP daemon.
Although they have somewhat similar appearance, it is absolutely different matters.

To use opendir, you have to open *a directory, not HTTP resource.

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.