You are here: Re: Photoalbum in PHP « PHP Language « IT news, forums, messages
Re: Photoalbum in PHP

Posted by J2be on 12/17/05 21:07

"Bernd Roth" <bernd.roth@chello.at> wrote in message
news:5564a$43a41e62$5472d23e$2258@news.chello.at...
> Hello NG,
>
> I want to wirte a photoalbum in php.
> So far I am now.
>
> <html>
> <body>
> <div>
> <?php
> $dirname="/srv/www/htdocs/dateien/";
> $dh = opendir($dirname);
> $file=array(readdir($dh));
> for($i=0;$i<4;++$i){
> print '<tr>'
> print '<td><img src="$file"></td>';
> print '</tr>';
> }
> closedir($dh);
> ?>
> </div>
> </body>
> </html>
>
> The problem now is that my HP only shows an empty image, as if apache
> cannot find any picture.
>
> Here we can see it:
>
> www.roth-bernd.com
>
> Can someone help me please with this error?
>
> Thanks in advance
>
> Friendly,
> Bernd





Your script is completely wrong, it's normal that it doesn't work.


for($i=0;$i<4;++$i){ /* The "for" is not a good solution to list the files
and a static limit (4) is useless*/

print '<td><img src="$file"></td>'; /*you've to read within the array
$file and not put it directly*/
/*If you use the ' quote php will not write the content of the variable
$file but the string $file*/

Your script will slow down your server if within the images folder there are
alot of files and/or alot of users
are visiting your site because the file listing requires alot of resources
if compared to other solutions.




You can view my sample script to have something working
and that use less resources because it does the directory listing only the
first time
and all other page loads are from the text file that will require a really
smaller amount of time.


-------------------------------------Code--------------------------------------------

<?PHP
$imagez = array();
$folderz = array();
$dirname="images/"; /*where are located the folders*/
$webdir="images/"; /*the relative webfolder*/
$imglist=$dirname . "imglist.txt"; /*the file where to store the names of
the images*/



if( file_exists($imglist) )
{
$imagez = file($imglist); //load from file! FASTER AND LESS RESOURCES
REQUIRED
} else {
$handle = opendir($dirname);

while ($file = readdir ($handle)) {
if (is_dir($webdir.$file)) {

if ( ($file == "..") or ($file == ".") ){continue;} /*exclude current
and up folders*/


$pushfld = $webdir . $file;
array_push ($folderz, $pushfld );
/*you can use the folders array to list images within subfolders! just
think! */
}
else
{
/*the extensions are up to you ....*/
if(eregi("^.*\.jpg$|^.*\.jpe|^.*\.jpeg|^.*\.gif$|^.*\.png|^.*\.swf|^.*\.mov|^.*\.avi|^.*\.mpg|^.*\.rm$",$file)) { $pushim = $webdir . $file; array_push ($imagez, $pushim ); } /*end of if eregi*/ } /*end of else*/ } /*end of while ($file = readdir ($handle))*/ if( $fp = @fopen($imglist, "w") ) { foreach ($imagez as $arro){ fputs($fp, $arro . "\n"); } } else { //die($cannot open the file //uncomment if you want to die if cannot write }} /*end of else*/?><html><body><div><!-- Html header --><?php/*that's up to you to create the code to show the images as you want*//*by using the array you dont' have to mix up alot of code with the html*/foreach ($imagez as $arro){ echo '<img src="' . $arro . '"><br>' . "\n";}?><!-- HTML Footer --></div></body></html>----------------------------------- End ofCode ------------------------------------------Have a nice day.------Leonardo Armando IarrussoJ2be - It Services for your BusinessP. IVA: 01319360622Via S. Spirito, 1982100 Benevento (BN) - ItalyTel/Fax: +39 0824 22887Mobile: +39 349 1482304e-mail: info[at]J2Be.comwww: http://www.J2Be.comSkype: j2be_it (info[at]J2Be.com)

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация