Author Topic: PHP image gallery help (echo (sub)folder)  (Read 1064 times)

Andreas J

  • Guest
PHP image gallery help (echo (sub)folder)
« on: August 20, 2010, 03:10:17 PM »
I have made a simple PHP image gallery where I save each users pictures in a folder with their usernames.
Like this for example:
images\USERNAME\originalpicture.jpg
images\USERNAME\thumbs\thumb_originalpicture.jpg

To show the users pictures I use a code that shows all files in the folder images\USERNAME\thumbs\

But I have been trying to figure out how to make a link on each thumbnail so they can click on it to see the original picture.


I NEED HELP, can't figure it out!
 
Code: [Select]

 
 <table border="0" width="600">
  <tr>
    <td>
<? $sessionnavn = $_SESSION['SESS_FIRST_NAME'];
echo '<h1>'.$sessionnavn.'`s album</h1>';
?>
<br>
<?php 

$files 
glob("images/".$sessionnavn."/thumbs/*.*"); for ($i=0$i<count($files); $i++) { $num $files[$i];

echo 
'<img src="'.$num.'" alt="Opplastet bilde"></a>'."&nbsp;&nbsp;"; } ?>


</td></th>
</table>

phphelp

  • Administrator
  • Senior Member
  • *****
  • Posts: 777
  • Karma: +3/-0
    • View Profile
    • PHP Help forum
Re: PHP image gallery help (echo (sub)folder)
« Reply #1 on: August 20, 2010, 03:33:25 PM »
You can use str_replace() function and apply it to thumbnail image path:

PHP Code: [Select]
$orig=str_replace('/thumbs/thumb_','/',$num);
echo 
'<a href="'.$orig.'" target="_blank"><img src="'.$num.'" alt="Opplastet bilde"></a>'."&nbsp;&nbsp;";



p.s. noticed small bug in your html code: you have opening <tr> but closing is </th>
Are you experienced in PHP programming and willing to share your knowledge?
Join us at php help forum!

nimesha

  • New Member
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: PHP image gallery help (echo (sub)folder)
« Reply #2 on: October 12, 2010, 04:20:14 AM »
PHP Code: [Select]

<table border="0" width="600">
    <
tr>
        <
td>
            <? 
$sessionnavn 'My';
            echo 
'<h1>'.$sessionnavn.' album</h1>';
            
?>
            <br>
            <?php

            $files 
glob("images/".$sessionnavn."/thumbs/*.*");
            for (
$i=0$i<count($files); $i++) {
                
$num $files[$i];
                echo 
'<a href="#"';
                echo 
' onClick=window.open("'.$num.'","myimage","width=600,height=600")';
                echo 
'><img src="'.$num.'" alt="Opplastet bilde" width="100" height="100"></a>'."&nbsp;&nbsp;";
            } 
?>

        </td></tr>
</table>