PDA

View Full Version : Why didn't working this code? pls help me :-(



joda
08-22-2009, 12:16 AM
Can somebody explain why this code didn't work for me?


<?php

$path = "./images/";

$dir_handle = @opendir($path) or die("Unable to open folder");

while (false !== ($file = readdir($dir_handle))) {

if($file == "index.php")
continue;
if($file == ".")
continue;
if($file == "..")
continue;

echo "<img src='$file' alt='$file'><br />";

}

closedir($dir_handle);


So,the problem is:
If I change the value of $path = "./"; instead of $path = "./images/"; it is working,but if I change it from $path = "./"; to $path = "./images/"; i got all the time this message:
"Unable to open folder"

Pls. can somebody explain me the right way to make path changing in PHP and how can I change my path from "images" to "thums" or backward?

Thnx a lot.

Mwnciau
08-22-2009, 02:15 AM
$dir_handle = @opendir($path) or die("Unable to open folder");

Rather than suppressing PHP's errors telling you what's wrong, try removing the @ and the or die clause allowing PHP to help you. I suspect that PHP doesn't have permission to access the folder in question, you'll need to CHMOD the correct permissions onto it.

Zangeel
08-22-2009, 02:53 AM
Make sure the directory is readable

whizard
08-22-2009, 03:12 AM
Make sure the directory is readable

But first, make sure your post is readable, and then we can be of more help.

Dan