Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Apr 2009
    Location
    Earth - sometimes sky :-)
    Posts
    121
    Thanks
    51
    Thanked 2 Times in 2 Posts

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

    Can somebody explain why this code didn't work for me?
    PHP Code:
    <?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.

  • #2
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    $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.

  • #3
    Regular Coder Zangeel's Avatar
    Join Date
    Oct 2007
    Location
    public_html/
    Posts
    638
    Thanks
    17
    Thanked 79 Times in 79 Posts
    Make sure the directory is readable
    PHP Code:
    $aString is_string((string)array()) ? true false// true :D 
    [/CENTER]

  • #4
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    Quote Originally Posted by Zangeel View Post
    Make sure the directory is readable
    But first, make sure your post is readable, and then we can be of more help.

    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •