Jump to content

PHP File/Image Browser


bubbasheeko

Recommended Posts

I am trying to come up with an easy way for a client to update their image gallery and came up with an idea....the problem?  Inexperience with file commands for php...

 

Here is the idea.

 

A folder is set up for the user - /photos/

 

They will create new directories - used as categories. 

 

Under each directory (category) they will upload images related to the directory name.

 

The site visitor will see a thumbnail of the first image in the directory acting as an 'icon'.  If they click on it they will then be able to see a thumbnails of each image under that directory.  They will be able to click on it and it will show up on screen.

 

Can anybody provide me with direction??  :)

Link to comment
Share on other sites

Okay...did some playing while I have been waiting :)

 

I came up with this...

 

<?php
if(isset($_GET['d']))
{
$path = "../photos/" . $_GET['d'] . "/";
$imgDir = opendir($path);
}
else
{
$path = "../photos/";
$imgDir = opendir($path);
}

while($imgName = readdir($imgDir)) 
{
if(is_dir($path . $imgName))
{
	if (($imgName != ".") && ($imgName != ".."))
	{
		echo "<a href=\"photo_test.php?d=" . $imgName . "\">". $imgName ."</a><br />";
	}
}
else
{

	if (($imgName != ".") && ($imgName != ".."))
	{
		echo '<a href="' . $path . $imgName . '">' . $imgName . '</a><br />';
	}
}
}
?>

 

Not sure if this is the right way, but it does work :)

 

I have separated the directories because I am going to be adding a nice listing using thumbnails...so I will see how that goes.

Link to comment
Share on other sites

hmm..I don't give myself enough credit.....

 

<?php
if(isset($_GET['d']))
{
$path = "../photos/" . $_GET['d'] . "/";
$imgDir = opendir($path);
}
else
{
$path = "../photos/";
$imgDir = opendir($path);
}
echo "<table width='600' colspan='2' rowspan='2' align='center'>";
$i=0; // COUNTER FOR TABLE BUILDER

while($imgName = readdir($imgDir)) 
{
$i++;
if($i == 1)
{
	echo "<tr>";
}
elseif($i == 6)
{
	echo "</tr><tr>";
	$i = 0;
}

if(is_dir($path . $imgName))
{
	if (($imgName != ".") && ($imgName != ".."))
	{
		echo '<td><a href="photo_test.php?d=' . $imgName . '"><img src="../images/PictureFolder.jpg" border="0"><br />' . $imgName . '</a></td>';
	}
}
else
{

	if (($imgName != ".") && ($imgName != ".."))
	{
		echo '<td><a href="' . $path . $imgName . '">' . $imgName . '</a></td>';
	}
}
}
echo "</tr></table>";
?>

 

Again...it may not be perfect...but it works :)

Link to comment
Share on other sites

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.