Page 1 of 1

flash gallery with php

Posted: Wed Oct 21, 2009 6:43 am
by sinans11
Hi
I have a problem that I can't seem to figure out for the past few days. Basically I downloaded a ridiculously cool flash gallery so I can view images on my website. The thing is I want to get the image location from sql database and only show certain images according to the gallery. my website works like this.
User end
1) Person clicks on gallery of choice.
2) All images assigned to that gallery are shown.
when an image is added the image is sent to server and location saved on sql along side the album that it belongs to via album ID.
Can some one please help out. The code is bellow

Code: Select all

 
<!-- Div that contains gallery. -->
<div id="gallery">
<!-- Script that embeds gallery. -->
<script language="javascript" type="text/javascript">
var so = new SWFObject("flashgallery.swf", "gallery", "800", "600", "8"); // You can change gallery width and height here or by styling div that contains gallery (use pixels or percents).
so.addParam("quality", "high");
so.addParam("allowFullScreen", "true");
so.addVariable("content_path","gallery"); // Location of a folder with JPG and PNG files (relative to php script) or a link to Flickr photostream (for example "http://www.flickr.com/photos/username/" or "http://www.flickr.com/photos/username/sets/setid/").
so.addVariable("color_path","default.xml"); // Location of xml file with settings.
so.addVariable("script_path","flashgallery.php"); // Location of php script (not requred if you work with Flickr).
so.write("gallery");
</script>
 
<br/>
 
<!-- 
Please place this link anywhere on the page that uses Flash Gallery.
You can style it anyway you want, but do not change or delete it.
Read the license! Thanks. :-)
-->
Powered by <a href="http://www.flash-gallery.org">Flash Gallery</a>
 
</body>
</html>
 

Code: Select all

<?php
$allowed_formats = array("jpg", "jpeg", "JPG", "JPEG", "png", "PNG");
$exclude_files = array(
"_derived",
"_private",
"_vti_cnf",
"_vti_pvt",
"vti_script",
"_vti_txt"
); // add any other folders or files you wish to exclude from the gallery.
 
$path = array();
 
if(isset($_GET['file_dir'])){
$file_dir = $_GET['file_dir'];
            $dir=opendir($file_dir);
                while ($file=readdir($dir))
                {
                $ext = substr($file, strpos($file, ".")+1);
                
                    if(array_search($file, $exclude_files)===false && array_search($ext, $allowed_formats)!==false){
 
$f=$file_dir.'/'.$file; 
 
$path []=$f;                    
 
                    }
                }
                
closedir($dir);
}
natcasesort($path);
 
print '<?xml version="1.0" encoding="iso-8859-1"?>';
print '<pics';
print '>';
 
$directory= $_SERVER['HTTP_HOST'] .$_SERVER['PHP_SELF'];
$directory=dirname($directory);
 
foreach ($path as $val) print '<pic src="'.'http://'.$directory.'/'.$val.'" title="'.$val.'" />';;
print "</pics>";
?>
 

Re: flash gallery with php

Posted: Wed Oct 21, 2009 11:13 am
by markusn00b
So... you want the gallery to be database driven, not file-system driven?

Re: flash gallery with php

Posted: Thu Oct 22, 2009 1:47 am
by sinans11
yes exactly but i cant seem to figure it out. can u please help or show the right direction

Re: flash gallery with php

Posted: Thu Oct 22, 2009 7:13 am
by markusn00b
sinans11 wrote:yes exactly but i cant seem to figure it out. can u please help or show the right direction
Okay. That's no problem - it's pretty easy, in fact. I'll assume you're working with a MySQL database.

Your images table setup would be something like:

Code: Select all

 
+--------+---------------------+------+-----+---------+----------------+
| Field  | Type                | Null | Key | Default | Extra          |
+--------+---------------------+------+-----+---------+----------------+
| id     | tinyint(5) unsigned | NO   | PRI | NULL    | auto_increment |
| path   | varchar(100)        | YES  |     | NULL    |                |
| gal_id | tinyint(5)          | YES  |     | NULL    |                |
+--------+---------------------+------+-----+---------+----------------+
 
And your gallery info table, something like:

Code: Select all

 
+-----------+--------------+------+-----+---------+----------------+
| Field     | Type         | Null | Key | Default | Extra          |
+-----------+--------------+------+-----+---------+----------------+
| id        | tinyint(5)   | NO   | PRI | NULL    | auto_increment |
| gal_alias | varchar(100) | YES  |     | NULL    |                |
| gal_name  | varchar(100) | YES  |     | NULL    |                |
+-----------+--------------+------+-----+---------+----------------+
 
gal_alias is unimportant here if you're searching for galleries based on their ID.

Anyhoo, to add a new image to the database, you'd run a simple INSERT SQL statement (I assume all variables have been previously set - $gal_id points to the ID of the gallery to which this new image belongs):

Code: Select all

 
INSERT INTO `database_name`.`images_table` (`path`, `gal_id`) VALUES ('$img_path', '$gal_id');
 
To delete an image (based on its ID):

Code: Select all

 
DELETE FROM `database_name`.`images_table` WHERE `id` = $img_id;
 
To grab all images from a certain gallery (based on the gallery ID):

Code: Select all

 
SELECT * FROM `database_name`.`images_table` WHERE `gal_id` = $gal_id;
 
To create a new gallery:

Code: Select all

 
INSERT INTO `database_name`.`galleries_table` (`gal_alias`, `gal_name`) VALUES ('$gal_alias', '$gal_name');
 
Other things like deleting whole galleries and their images should be deduce-able from the above examples.

Let me know if you need any further help.

Thanks,
Mark.