peps03
asked on
strip directory name and extension from file name
Hi,
I use this script to get pictures from a folder and display them.
I would like to strip the directory-name and the extension from "$num" (IN THE TITLE TAG) so the title will have the picture name only.
thanks a lot!
I use this script to get pictures from a folder and display them.
I would like to strip the directory-name and the extension from "$num" (IN THE TITLE TAG) so the title will have the picture name only.
thanks a lot!
<?php
$files = glob("pictures/*.*");
$files = array_reverse($files); for ($i=0; $i<count($files); $i++) { $num = $files[$i];
echo "<a href='".$num."' rel='shadowbox[Mobile]' title=\"". $num ." | Navigate with the ‹— and —› arrowbuttons.\"><img src='imgsize.php?h=75&img=".$num."' style='border: solid 1px black;'></a> ";}
?>
Are there further directories within the pictures folder?
This should do the trick:
$path = "/home/httpd/html/index.ph p";
$file = basename($path);
$file=substr($file,0,strrp os($file,' .'));
echo $file;
$path = "/home/httpd/html/index.ph
$file = basename($path);
$file=substr($file,0,strrp
echo $file;
if all files have the same extension, e.g. ".jpg" you can provide this to basename() and you get the filename without extension.
$path = "/mydir/images/myimage.jpg ";
$filename = basename($path, '.jpg');
echo $filename;
gives this output:
myimage
$path = "/mydir/images/myimage.jpg
$filename = basename($path, '.jpg');
echo $filename;
gives this output:
myimage
ASKER
thanks ziceva, but i dont really get it.
how do i fit that in the code above? --> title=\"". $num ."
the num has to be stripped from dir-name and .jpg
@quitar7man: no
thanks!
how do i fit that in the code above? --> title=\"". $num ."
the num has to be stripped from dir-name and .jpg
@quitar7man: no
thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a lot Ziceva!
It works great!
It works great!