how to display pictures

Discussion in 'PHP' started by dougvcd, Jun 8, 2009.

  1. #1
    i have a folder on my server with pics in it and i want to be able to display them on a web page and havnt got a clue where to start
    any info please
    Doug
     
    dougvcd, Jun 8, 2009 IP
  2. osmasters

    osmasters Well-Known Member

    Messages:
    453
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    100
    #2
    you can display it by below code
    <img src="folder/abc.jpg"> or <img src="folder/abc.jpg" width='500' height='500'>
     
    osmasters, Jun 8, 2009 IP
  3. dougvcd

    dougvcd Peon

    Messages:
    267
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    with this code i have to write in all names
    is there a way to dislay all without having to name them all in code
    cheers
    Doug
     
    dougvcd, Jun 8, 2009 IP
  4. dougvcd

    dougvcd Peon

    Messages:
    267
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    ok this is what i have so far puts pics on page but dont line up very well
    and would like a name displayed with each pic

    //Outputs the image and other data

    
    Echo " ".$info['pet'] . " <br>";
    Echo "<img src=http://www.hire.co.uk/pics/".$info['pic'] ." alt=\"Image\" align=\"left\" width=\"200px\" height=\"150px\" hspace=\"10px\" vspace=\"8px\"> <br/>";
    PHP:
    cheers
    Doug
     

    Attached Files:

    dougvcd, Jun 8, 2009 IP
  5. givemeknol

    givemeknol Active Member

    Messages:
    22
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    88
    #5
    You browse the directory (using dir function) to get all file names, and after display them on your web.
     
    givemeknol, Jun 8, 2009 IP
  6. clarky_y2k3

    clarky_y2k3 Well-Known Member

    Messages:
    114
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    108
    #6
    Here's something I wrote quickly to show images in a directory in a tabular format.

    Note that it does not work recursively, that is, it will not traverse sub-directories.

    <table>
      <tr>
    <?php
    // Path to images
    $sPath = './';
    // Number to show per row
    $iNum = 3;
    // Allowed images
    $aImages = array('jpg', 'jpeg', 'gif', 'png');
    
    // Open the directory
    $rDir = opendir($sPath);
    
    // Initalise a counter for number of images
    $iCount = 0;
    
    // Loop over directory
    while( ($sFile = readdir($rDir)) !== false )
    {
        // Add path to filename
        $sFile = $sPath . $sFile;
        // Get file extension
        $sExt  = strtolower(pathinfo($sFile, PATHINFO_EXTENSION));
    
        // If it is an image...
        if ( in_array($sExt, $aImages) )
        {
            // Increase counter and check if it is neccessary to start a new row
            if ( $iCount++ % $iNum == 0 && $iCount > 1 )
            {
                echo '  </tr>' . "\n\n";
                echo '  <tr>' . "\n";
            }     
         
            // ...add image into table cell
            echo '    <td><img src="' . $sFile . '"></td>' . "\n";
        }
    }
    
    // If there are no images...
    if ( $iCount == 0 )
    {
        // ...output a message saying so
        echo '    <td>No images to display</td>' . "\n";   
    }
    else
    {
        // ...otherwise complete the table by adding blank cells
        
        // Calculate how many blank cells are required
        $iLeft = $iNum - ($iCount % $iNum);
        // If anything other than a whole row is required...
        if ( $iLeft < $iNum )
        {
            // ...add the blank cells as many times as neccessary
            for($i = 0; $i < $iLeft; ++$i)
            {
                echo '    <td>&nbsp;</td>' . "\n";
            }
        }
    }
    ?>
      </tr>
    </table>
    PHP:
     
    clarky_y2k3, Jun 8, 2009 IP
  7. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #7
    exec('ls /dirname', $result);
     
    gapz101, Jun 9, 2009 IP
  8. Social.Network

    Social.Network Member

    Messages:
    517
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    35
    #8
    Social.Network, Jun 9, 2009 IP
  9. ezprint2008

    ezprint2008 Well-Known Member

    Messages:
    611
    Likes Received:
    15
    Best Answers:
    2
    Trophy Points:
    140
    Digital Goods:
    1
    #9
    how they're displayed will depend on how you use HTML basic design code
    in the echo statement where it shows <br> ..thats a page break or (next line) so all your images are probably stacked vertically. If its displaying your images and you don't like how it displays them , then add HTML code to the echo statement. and be careful of double quotations so you dont get errors. :D
     
    ezprint2008, Jun 10, 2009 IP