Jump to content

Recommended Posts

Having thinking issues.... Just a stupid simple question I'm just having issues wrapping head around for some dumb reason.....

 

Using this code here.

 


$file = $fileinfo->getFilename(); //prints file
        	$path = $fileinfo->getPath(); // get path

        	$pic_name = $fileinfo->getBasename('.jpg');
        	echo ('<li><span class="file"><a href="'.$path.'/'.$file.'" title="'.$pic_name.'" rel="gb_imageset['.$SetName.']">'.$picname.'</a></span></li>');

 

the structure setup is as such a folder with subfolders as follows:

MPOP     ------- Parent folder
THUMBS -------- child to MPOP folder
A - L      --------- child to MPOP folder
M - Z     --------- child to MPOP folder

 

The above code is within a recursive function that creates the links... works great not a problem but how would I get the THUMBS be displayed instead of the file name as the link. Thumbs name in the THUMBS folder is the same but has "TN_" as a prefix to the file name.

 

 

Below is the entire function if curious in that btw:

function Tree_Photo($tree_path, $orig_path, $SetName)
{

$I_T_H = NULL; // I_T_H used to detect of there is anything to list. Else main program displays something like a message or the like.
$iterator = new DirectoryIterator($tree_path);
foreach ($iterator as $fileinfo) 
{
    if ($fileinfo->isFile() && $fileinfo!= 'struct.php' && $fileinfo!='index.php'&& $fileinfo!='index.htm'&& $fileinfo!='index.html'&& $fileinfo!='Thumbs.db') 
    	{
        	$file = $fileinfo->getFilename(); //prints file
        	$path = $fileinfo->getPath(); // get path
        	//echo $file."<br>";

        	//$file_array = explode(".",$file);  // WAS USED TO REMOVE SUFFIX BUT NAMES HAVE "." in them too
        	//$pic_name = $file_array[0];
        	$pic_name = $fileinfo->getBasename('.jpg');
        	echo ('<li><span class="file"><a href="'.$path.'/'.$file.'" title="'.$pic_name.'" rel="gb_imageset['.$SetName.']"><img src="'.$file.'" alt="'.$picname.'"></a></span></li>');
        	//<a href="/index/Photos/Hourly Employee Photos/A - D/Ambroziak, Mike.jpg" title="Ambroziak, Mike" rel="gb_imageset[NAME]">HTML</a>
		//<a href="/index/Photos/Hourly Employee Photos/A - D/Adams, John.jpg" title="Adams, John" rel="gb_imageset[NAME]">HTML</a>	
    
        	$I_T_H = 1;
    	}	
    	//echo $orig_path;
    	if($fileinfo->isDir()&&$fileinfo != $orig_path)
	{
		if($fileinfo->isDot()) continue; //bypasses . & ..

		$folder = $fileinfo->getFilename(); //prints directory//

		if($folder == "Obsolete") continue; //bypasses Obsolete folders
		if($folder == "THUMBS") continue; //bypasses THUMBS for now

        	//echo "D->".$folder."<br>";
        	echo('<li><span class="folder"><strong>'.$folder.'</strong></span>
				<ul>');
        	//<li><span class="folder"><strong>Home</strong></span>
		//<ul>
        	Tree_Photo($tree_path."/".$folder,$orig_path,$SetName);
        	echo "</ul>";
        	$I_T_H = 1;
	}


}// end of foreach

return $I_T_H;

Link to comment
https://forums.phpfreaks.com/topic/193771-getting-a-path-directoryiteratorgetpath/
Share on other sites

Sorry, yeah that's a bit off isn't it. tired...

 

I want to replace this line here: <img src="'.$file.'" alt="'.$picname.'">

So I can display the thumb picture from the THUMBS folder.

 

This function makes a dynamic list of links for pictures, I want the links to be the thumb pictures that are stored in the THUMBS folder. that img link there now does nothing because it's a dead link as it is, since I'm not pointing the path to the Thumbs picture....  what I need help getting is the path of the THUMBS folder dynamically. So I can say something like this: <img src="'.$thumb_path.'/'.$file.'" alt="'.$picname.'">  It's the $thumb_path part I'm lost in confusion with. 

 

Using $path = $fileinfo->getPath();  Will get me the path to particular item but I need the path to get that is one back named THUMBS where a file will be identicaly named in there of the larger picture.

 

 

 

Correction: ignore this comment as it is not how its setup----"Thumbs name in the THUMBS folder is the same but has "TN_" as a prefix to the file name."

 

Did it with this... wow I am not thinking straight today. Thanks for trying to help though.

$pic_name = $fileinfo->getBasename('.jpg');
        	$thumbnailer = explode("/",$path);
        	array_pop($thumbnailer);
        	$thumbnailer = implode("/",$thumbnailer);
        	$thumbnailer = $thumbnailer.'/THUMBS/'.$file;
      
        	echo ('<li><span class="file"><a href="'.$path.'/'.$file.'" title="'.$pic_name.'" rel="gb_imageset['.$SetName.']"><img src="'.$thumbnailer.'" alt="'.$picname.'"></a></span></li>');

That is more of what I was looking for actually didn't want to do explode just because... but it was a couple lines so broke down and used it.  And I may end up taking you up on that offer... could have used a reference when I first discovered directoyiterator a few months ago haha. Thanks btw.

Perhaps you could instead just use $thumbnailer = dirname($path) . '/THUMBS/' . $pic_name

If you need any more help with the DirectoryIterator feel free to ask, I literally wrote the manual for it. :shy:

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.