fill gallery reading png files in dir php -


i have dir structure like:

images/        imgex2.png        s_imgex2.png        imgre.png        s_imgre.png 

where imgex2.png , imgre.png big images , s_imgex2.png , s_imgre.png thumbnails

i want fill gallery absolute path in php like

<li><a href="www.site.com/images/imgex2.png">     <img src="images/s_imgex2.png" alt="ex2" /> </a></li> <li><a href="www.site.com/images/imgre.png">     <img src="images/s_re.png" alt="re" /> </a></li> 

how fill given path gallery big image first , thumbnail (it has "s_" @ begining of filename) , put in alt="" name without "img" string? issue here not filenames have "img" trim not option

other problem getcwd() returns 'file:///d:/hosting/2543486/html/site/images' not www.mysite.com

i doing

<? $dir = './'; $files = glob( $dir . '*.png'); foreach( $files $file) {     $path  = getcwd().$file;     $path  = substr_replace($path, 'file:///d:/hosting/2543486/html/', 0);       $site       = "http://www.site.com/".$path.$file;     $thumb_site = "http://www.site.com/".'s_'.$path.$file;     $alt        = substr_replace($file, 'img', 0);       echo '<li><a href="'.$thumb_site.'">';     echo '    <img src="'.$thumb_path.'" alt="'.$alt.'" />';     echo '</a></li>';   } ?> 

but getting:

http://www.site.com/file:///d:/hosting/2543486/html/site/imgex2.png http://www.site.com/s_file:///d:/hosting/2543486/html/site/imgex2.png 

how solve it?

i go this:

$dir = './'; $files = glob( $dir . 's_*.png'); foreach( $files $file) {      $site       = "/images/".str_replace("s_","",$file);     $thumb_site = "/images/".$file;     $alt        = str_replace(".png","",str_replace("s_img","",$file));       echo '<li><a href="'.htmlentities($site,ent_compat,"utf-8").'">';     echo '    <img src="'.htmlentities($thumb_site,ent_compat,"utf-8").'" alt="'.htmlentities($alt,ent_compat,"utf-8").'" />';     echo '</a></li>';   } 

edit:

if really want use absolute path, change little bit:

$root="http://www.example.com"; $dir = './'; $files = glob( $dir . 's_*.png'); foreach( $files $file) {      $site       = $root."/images/".str_replace("s_","",$file);     $thumb_site = $root."/images/".$file;     $alt        = str_replace(".png","",str_replace("s_img","",$file));       echo '<li><a href="'.htmlentities($site,ent_compat,"utf-8").'">';     echo '    <img src="'.htmlentities($thumb_site,ent_compat,"utf-8").'" alt="'.htmlentities($alt,ent_compat,"utf-8").'" />';     echo '</a></li>';   } 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -