www.webdeveloper.com
Results 1 to 5 of 5

Thread: Php Image display help

  1. #1
    Join Date
    Jul 2011
    Posts
    5

    Php Image display help

    I have a page whr pictures r been displayed from the directory..
    So when imgs r dr in directory it gets displayed in a page thru php code... Problem is whn dr s no image in dat directory den i get long error.. it irritates..

    Codes are below-

    <?php
    $dirname = "directory-name/";

    $images = scandir($dirname);
    $ignore = Array(".", "..");
    foreach($images as $curimg){
    if(!in_array($curimg, $ignore)) {
    echo "<img src='directory-name/$curimg' /><br/>
    <br/>
    \n";

    };
    }
    ?>


    Please help me in displaying CUSTOM ERROR MSG IF NO images found in dat directory.

  2. #2
    Join Date
    Jul 2011
    Location
    Haarlem
    Posts
    30
    echo <img src="directory-name/$curimg"/> . "<br/> <br/>";

    There you go.
    "" doesn't allow image to be shown, you must use it this way.

  3. #3
    Join Date
    Jul 2011
    Posts
    5
    I guess u didnt understand wt i meant to say...

    I want da imgs to be displayed from da directory n it gets displayed..
    but whn dr r no imgs in dat directory n whn i open dat page i get error like --

    Warning: scandir(snaps/) [function.scandir]: The system cannot find the path specified. (code: 3) in C:\xampp\htdocs\omg\images.php on line 337

    So wt i wanna is i dont want this error to be displayed anytime.. even if dr r no imgs in dat directory.. i hope u understood wt i m saying,.

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,145
    Wrap the code in an if block that tests the directory name before trying to scan it:
    PHP Code:
    $dirname "directory-name/";
    // use "@" to suppress warnings from is_dir() and is_readable():
    if(@is_dir($dirname) && @is_readable($dirname)) {
       
    // do your stuff here

    PS: I'd suggest using proper English here instd of da chat shorthand, both to look more professional and to help those here for whom English is not their first language.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Jul 2011
    Posts
    5
    Thanks a lot .. Need a favour from you.. please help..
    Using same above Code
    - Can we display the image name below each n every imgs?
    - Is thr any way to display no of files in directory..?
    - Using above codes shws da images when there are files in directory n if not den nthn gets displayed dats fine.. but is it possible that when thr is no image to show some msg ? (onli when dr s no images in dat directory)

    PLEASE HELP..

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles