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 10 of 10
  1. #1
    Regular Coder jfreak53's Avatar
    Join Date
    May 2004
    Location
    Guatemala
    Posts
    477
    Thanks
    19
    Thanked 10 Times in 10 Posts

    Making a small page

    I need a small PHP driven page that will do one and only one thing, I need it to keep a list of certain images I have in a directory and when I call it with a certain parameter display that image as a page with some code I add after words, basically all it has to be is an image display page, I need the full code for this if anyone can help please?

  • #2
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Fell free to dress it with HTML
    PHP Code:
    <?php
    // This is the directory in which the images reside.
    $dir "/tmp/";

    // Open a known directory, and proceed to read its contents
    if (is_dir($dir)) {
       if (
    $dh opendir($dir)) {
           while ((
    $file readdir($dir)) !== false) {
                     if( 
    preg_match('/^\.(bmp|jpe?g|gif|png)$/i'$extension) ) {  // check the file is an image 
            
    echo $dir $filename;                               // if it is, add it to the array 
          


           }
           
    closedir($dh);
       }
    }
    ?>

  • #3
    Regular Coder jfreak53's Avatar
    Join Date
    May 2004
    Location
    Guatemala
    Posts
    477
    Thanks
    19
    Thanked 10 Times in 10 Posts
    Thank for the help...Just one problem, I don't think I specified myself the right way the first time, sorry my fault, I was in a hurry to leave, I had to go do something, so now I will exand on what I need exactly, what I need is a page like that, that I can call from a browser window let's say and call it with parameters like this, this is an example "displayimage.php?pid=1" or 2 or 3 depending on how many pics I have and somewhere in the file have a list of pics with their respective numbers, and further down have the HTML code for the page that will be displayed in the browser.

  • #4
    Regular Coder trib4lmaniac's Avatar
    Join Date
    Feb 2004
    Location
    Cornwall, UK
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What about "displayimage.php?src=picture.jpg"? You could make that easily by expanding on the above code.

  • #5
    Regular Coder jfreak53's Avatar
    Join Date
    May 2004
    Location
    Guatemala
    Posts
    477
    Thanks
    19
    Thanked 10 Times in 10 Posts
    that would work too...but the only problem is I don't want the users to see the image name...that's the thing...by the way where would I add my HTML Code in the code above?

  • #6
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Um they will be able to find your image name even if you do it with numbers (in the HTML source). There are other ways of securing images.

  • #7
    Regular Coder jfreak53's Avatar
    Join Date
    May 2004
    Location
    Guatemala
    Posts
    477
    Thanks
    19
    Thanked 10 Times in 10 Posts
    Ok, well where would I add my HTML Code for the page...I need to add full header info since I have some JavaScript in the page?

  • #8
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Above the <?php and below the ?> tag.

  • #9
    Regular Coder jfreak53's Avatar
    Join Date
    May 2004
    Location
    Guatemala
    Posts
    477
    Thanks
    19
    Thanked 10 Times in 10 Posts
    Ok, first I would like to thank you guys for all your help, second I'm sorry to be such a pain but need some more help guys. Ok I uploaded my page to the site, and this is the code of the page "one.php":

    Code:
    <html>
    <head>
    <title>Pics</title>
    </head>
    
    <script type="text/javascript" src="scripts.js"></script>
    
    <script language="JavaScript" type="text/JavaScript">
    adjust_popup();
    </script>
    
    <body>
    <?php
    // This is the directory in which the images reside.
    $dir = "/done/im/";
    
    // Open a known directory, and proceed to read its contents
    if (is_dir($dir)) {
       if ($dh = opendir($dir)) {
           while (($file = readdir($dir)) !== false) {
                     if( preg_match('/^\.(bmp|jpe?g|gif|png)$/i', $extension) ) {  // check the file is an image
            echo $dir . $filename;                               // if it is, add it to the array
          }
    
           }
           closedir($dh);
       }
    }
    ?>
    </body>
    </html>
    That's the code, now it's under the directory done/im with the pics the same dir, which I have it entered there, this is from the root dir, when I run it without any commands nothing, when I try commands like "one.php?src=1.jpg" nothing, I've also tried "filename", "file" nothing it will not pull up the images, the images are named 1.jpg and 2.jpg, what do I have to add to this to get it work this way, please help?

  • #10
    Regular Coder trib4lmaniac's Avatar
    Join Date
    Feb 2004
    Location
    Cornwall, UK
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm not sure if the path to the image directory has to be from the very root. In which case it would be a bit different (but I can't tell you what because it's your server). If you can make it a relative path you could try that, or find out the absolute path.

    Also the line
    PHP Code:
    echo $dir $filename;  // if it is, add it to the array 
    is not actually affecting an array.
    Change it to something like
    PHP Code:
    $img_array[] = $dir $filename
    You may have to initalise it first. (With "$img_array = array();")
    Then don't for get to echo the src that you want.
    Last edited by trib4lmaniac; 10-26-2004 at 01:23 AM.


  •  

    Posting Permissions

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