godyn Posted August 4, 2009 Share Posted August 4, 2009 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 More sharing options...
jonsjava Posted August 4, 2009 Share Posted August 4, 2009 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>'; ?> Link to comment https://forums.phpfreaks.com/topic/168792-im-stuck-with-the-php-for-tiltgallery/#findComment-890533 Share on other sites More sharing options...
godyn Posted August 4, 2009 Author Share Posted August 4, 2009 It's seems I can learn allot from that ! :-) Thanks so much !!! Looking forward to the random so I can try it out. Can I buy you a paypal beer? :-) Link to comment https://forums.phpfreaks.com/topic/168792-im-stuck-with-the-php-for-tiltgallery/#findComment-890537 Share on other sites More sharing options...
jonsjava Posted August 4, 2009 Share Posted August 4, 2009 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.) Link to comment https://forums.phpfreaks.com/topic/168792-im-stuck-with-the-php-for-tiltgallery/#findComment-890543 Share on other sites More sharing options...
jonsjava Posted August 4, 2009 Share Posted August 4, 2009 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>'; ?> Link to comment https://forums.phpfreaks.com/topic/168792-im-stuck-with-the-php-for-tiltgallery/#findComment-890546 Share on other sites More sharing options...
godyn Posted August 4, 2009 Author Share Posted August 4, 2009 somehow that doesn't work :-/ could it be the echo <<<EOF Link to comment https://forums.phpfreaks.com/topic/168792-im-stuck-with-the-php-for-tiltgallery/#findComment-890627 Share on other sites More sharing options...
jonsjava Posted August 4, 2009 Share Posted August 4, 2009 um...nope. That's just a simple way to echo. Called HEREDoc syntax. Can you tell me the errors you receive? Link to comment https://forums.phpfreaks.com/topic/168792-im-stuck-with-the-php-for-tiltgallery/#findComment-890631 Share on other sites More sharing options...
jonsjava Posted August 4, 2009 Share Posted August 4, 2009 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>'; ?> Link to comment https://forums.phpfreaks.com/topic/168792-im-stuck-with-the-php-for-tiltgallery/#findComment-890639 Share on other sites More sharing options...
jonsjava Posted August 4, 2009 Share Posted August 4, 2009 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 Link to comment https://forums.phpfreaks.com/topic/168792-im-stuck-with-the-php-for-tiltgallery/#findComment-890642 Share on other sites More sharing options...
godyn Posted August 5, 2009 Author Share Posted August 5, 2009 super, man ! thanks for your time and fast response. Link to comment https://forums.phpfreaks.com/topic/168792-im-stuck-with-the-php-for-tiltgallery/#findComment-891105 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.