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
you can display it by below code <img src="folder/abc.jpg"> or <img src="folder/abc.jpg" width='500' height='500'>
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
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
You browse the directory (using dir function) to get all file names, and after display them on your web.
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> </td>' . "\n"; } } } ?> </tr> </table> PHP:
Have you considered an open-source solution? There are MANY gallery scripts available. I use ImageView @ http://www.blackdot.be/?inc=projects/imageview.
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.