Jump to content

I'm stuck with the php for tiltgallery


godyn

Recommended Posts

Hello folks,

 

After some experimenting I finally got the php working for tiltviewer flash gallery to load the pictures via php instad via xml file.

 

Only I have some other things I want solved.

 

I would like that the script only shows pictures that begin with

photo' or 'picture' and between sizes.(kb)

 

example:

 

IF afbeelding

begint met 'picture' or 'photo'

AND afbeelding < 200kb AND >20Kb

THEN 'toon de foto' (dus scriptje uitvoeren'

ELSE niets (of niet tonen)

 

this is the script, I would be in heaven if s.b. would help me out with this.

 

I also would like the images to be random (I think now he follow the directory (from the array?)

 

<?php
function GetDirArray($folder) {
   $handle=opendir($folder);
   while ($file=readdir($handle)) {
      if ($file!="." && $file!="..") {
         $ret[count($ret)]=$file;
      }
   }
   closedir($handle);
   sort($ret);
   return $ret;
}
$gallery=GetDirArray('../media/uploads');
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<tiltviewergallery>';
echo '<photos>';
for ($i=0; $i<sizeof($gallery); $i++)
{
   echo '<photo imageurl="../media/uploads/'.$gallery[$i].'"><title></title><description></description></photo>';
}
echo '</photos>';
echo '</tiltviewergallery>';
?> 

Link to comment
https://forums.phpfreaks.com/topic/168792-im-stuck-with-the-php-for-tiltgallery/
Share on other sites

I haven't had a chance to test this script, but the idea is sound.  Basically, you add a strstr or stristr (search string) in your if statement, to parse out the unwanted files.  I'll add the randomness in a second, but for now, this is what I have.

<?php
function GetDirArray($folder) {
   $handle=opendir($folder);
   while ($file=readdir($handle)) {
      if ($file!="." && $file!=".." && (stristr($file, "photo", "") || stristr($file, "picture", ""))) {
         $ret[count($ret)]=$file;
      }
   }
   closedir($handle);
   sort($ret);
   return $ret;
}
$gallery=GetDirArray('../media/uploads');
echo <<<EOF
<?xml version="1.0" encoding="UTF-8"?>';
<tiltviewergallery>
<photos>
EOF;
for ($i=0; $i<sizeof($gallery); $i++)
{
   echo '\t\t<photo imageurl="../media/uploads/'.$gallery[$i].'"><title></title><description></description></photo>';
}
echo '\t</photos>';
echo '</tiltviewergallery>';
?> 

here's the randomization. I hope this is what you were looking for.

<?php
function GetDirArray($folder) {
   $handle=opendir($folder);
   while ($file=readdir($handle)) {
      if ($file!="." && $file!=".." && (stristr($file, "photo", "") || stristr($file, "picture", ""))) {
         $ret[count($ret)]=$file;
      }
   }
   closedir($handle);
   sort($ret);
   return $ret;
}
$gallery=GetDirArray('../media/uploads');
echo <<<EOF
<?xml version="1.0" encoding="UTF-8"?>';
<tiltviewergallery>
<photos>
EOF;
shuffle($gallery);
for ($i=0; $i<sizeof($gallery); $i++)
{
   echo '\t\t<photo imageurl="../media/uploads/'.$gallery[$i].'"><title></title><description></description></photo>';
}
echo '\t</photos>';
echo '</tiltviewergallery>';

?> 

I'll always go for a paypal beer, but it's not required.  just hit up my website (located in my sig.)

one sec. forgot to calculate filesize.

<?php
function GetDirArray($folder) {
   $handle=opendir($folder);
   while ($file=readdir($handle)) {
      if ($file!="." && $file!=".." && (stristr($file, "photo", "") || stristr($file, "picture", "")) && (filesize($folder.$file) <= 25600 && filesize($folder.$file) >= 2560)) {
         $ret[count($ret)]=$file;
      }
   }
   closedir($handle);
   sort($ret);
   return $ret;
}
$gallery=GetDirArray('../media/uploads');
echo <<<EOF
<?xml version="1.0" encoding="UTF-8"?>';
<tiltviewergallery>
<photos>
EOF;
shuffle($gallery);
for ($i=0; $i<sizeof($gallery); $i++)
{
   echo '\t\t<photo imageurl="../media/uploads/'.$gallery[$i].'"><title></title><description></description></photo>';
}
echo '\t</photos>';
echo '</tiltviewergallery>';

?> 

try this:

<?php
function GetDirArray($folder) {
   $handle=opendir($folder);
   while ($file=readdir($handle)) {
      if ($file!="." && $file!=".." && (stristr($file, "photo") || stristr($file, "picture")) && (filesize($folder.$file) <= 25600 && filesize($folder.$file) >= 2560) && (stristr($file, ".jpg") || stristr($file,".jpeg") || stristr($file, ".png") || stristr($file, ".gif"))) {
         $ret[count($ret)]=$file;
      }
   }
   closedir($handle);
   sort($ret);
   return $ret;
}
$gallery=GetDirArray('../media/uploads');
echo <<<EOF
<?xml version="1.0" encoding="UTF-8"?>';
<tiltviewergallery>
   <photos>
EOF;
shuffle($gallery);
for ($i=0; $i<sizeof($gallery); $i++)
{
   echo '\t\t<photo imageurl="../media/uploads/'.$gallery[$i].'"><title></title><description></description></photo>';
}
echo '\t</photos>';
echo '</tiltviewergallery>';

?> 

ok, I've tested this script on my development box, and I know it to work

<?php
function GetDirArray($folder) {
   $handle=opendir($folder);
   while ($file=readdir($handle)) {
      if ($file!="." && $file!=".." && (stristr($file, "photo") || stristr($file, "picture")) && (filesize($folder.$file) <= 25600 && filesize($folder.$file) >= 2560) && (stristr($file, ".jpg") || stristr($file,".jpeg") || stristr($file, ".png") || stristr($file, ".gif"))) {
         $ret[count($ret)]=$file;
      }
   }
   closedir($handle);
   sort($ret);
   return $ret;
}
$gallery=GetDirArray('../media/uploads');
echo <<<EOF
<?xml version="1.0" encoding="UTF-8"?>';
<tiltviewergallery>
   <photos>
EOF;
shuffle($gallery);
for ($i=0; $i<sizeof($gallery); $i++)
{
   echo "\n\t\t<photo imageurl=\"../media/uploads/".$gallery[$i]."\">\n\t\t\t<title></title>\n\t\t\t<description></description>\n\t\t</photo>";
}
echo "\n\t</photos>";
echo '</tiltviewergallery>';

?>

the previous version worked, but I like clean XML

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.