guest1234 Posted April 29, 2009 Share Posted April 29, 2009 ok so here is my code for a lightbox image gallery written in php <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>test</title> <link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" /> <script type="text/javascript" src="js/prototype.js"></script> <script type="text/javascript" src="js/scriptaculous.js?load=effects"></script> <script type="text/javascript" src="js/lightbox.js"></script> </head> <body> <?php $dir = "../public_html/images/banner_thumbnail/"; $dh = opendir($dir); while($filename = readdir($dh)) { $filepath = $dir.$filename; if(is_file($filepath) and ereg("\.jpg$",$filename)) { $gallery[] = $filepath; } } sort($gallery); $dir2 = "../public_html/images/banner/"; $dh2 = opendir($dir2); while($filename2 = readdir($dh2)) { $filepath2 = $dir2.$filename2; if(is_file($filepath2) and ereg("\.jpg$",$filename2)) { $gallery2[] = $filepath2; } } sort($gallery2); foreach($gallery as $image) foreach($gallery2 as $images) { $img = "<a href='$images' rel='lightbox[roadtrip]' title= ' '>"; $thumbnail = "<img src='$image' border='0'></a>"; $joinimg = $img.$thumbnail; echo $joinimg; echo "\n"; } ?> </body> </html> the problem is that when this page is accessed there are abunch of broken linked images on the page and when i right click on one of them and go to properties and look at the link it is for example: http://costawurks.com/public_html/images/banner/... .jpg and the problem is that the images are not found in ../public_html/images/banner/... .jpg they are really found in just ../images/banner/... .jpg. when i go to the php code and change the $dir and $dir2 and take out public_html/ and just have ../images/banner/... .jpg nothing shows up on the screen after and the when i check the source code is empty. Any idea what the problem is and how to fix it Thank you in advanced Link to comment https://forums.phpfreaks.com/topic/156053-no-images-showing-up/ Share on other sites More sharing options...
xtopolis Posted April 29, 2009 Share Posted April 29, 2009 why do you have: foreach() ... foreach() { } It might just be me, but I don't think that works. Also, consider using glob to scrape the directory folders, and don't use ereg as it's becoming depreciated. This example may help you: however , it assumes that the sizes of each array will be the same <?php error_reporting(E_ALL); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>test</title> </head> <body> <?php $dir = "../../imgs/"; $gallery = glob("$dir*.jpg"); sort($gallery); $dir2 = "../../otherimgs/"; $gallery2 = glob("$dir2*.jpg"); sort($gallery2); $imgs = array_combine($gallery, $gallery2); foreach($imgs as $k => $v) { echo "<a href='" . $dir . $k . "' rel='lightbox[roadtrip]' title= ' '>"; echo "<img src='" . $dir2 . $v . "' border='0'></a>"; echo "\n"; } ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/156053-no-images-showing-up/#findComment-821535 Share on other sites More sharing options...
guest1234 Posted April 29, 2009 Author Share Posted April 29, 2009 thank you for the reply so what i did was copy and paste the code example you gave me and i changed the dir's here is what i have now <?php error_reporting(E_ALL); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>test</title> </head> <body> <?php $dir = "../../images/banner_thumbnail/"; $gallery = glob("$dir*.jpg"); sort($gallery); $dir2 = "../../images/banner/"; $gallery2 = glob("$dir2*.jpg"); sort($gallery2); $imgs = array_combine($gallery, $gallery2); foreach($imgs as $k => $v) { echo "<a href='" . $dir . $k . "' rel='lightbox[roadtrip]' title= ' '>"; echo "<img src='" . $dir2 . $v . "' border='0'></a>"; echo "\n"; } ?> </body> </html> now when i go on that page here are the errors i get Warning: sort() expects parameter 1 to be array, boolean given in /home/costawur/public_html/filetest.php on line 17 Warning: sort() expects parameter 1 to be array, boolean given in /home/costawur/public_html/filetest.php on line 22 Warning: array_combine() expects parameter 1 to be array, boolean given in /home/costawur/public_html/filetest.php on line 25 Warning: Invalid argument supplied for foreach() in /home/costawur/public_html/filetest.php on line 28 NOTE: just wanted to point out im new to php and im learning as i go and reading PHP & MySQL for dummies Link to comment https://forums.phpfreaks.com/topic/156053-no-images-showing-up/#findComment-821542 Share on other sites More sharing options...
xtopolis Posted April 29, 2009 Share Posted April 29, 2009 The first two errors are because it cannot find the directory, try putting YOUR directories back in there. $dir = "../public_html/images/banner_thumbnail/"; $dir2 = "../public_html/images/banner/"; Realize that the "../" means "go up one directory from this scripts location". Therefore you should be sure you are pointing to the correct path in general, because the errors from your first script note otherwise. So if those map correctly, then my example assumes the each directory will have the EXACT same number of images. Otherwise we'll have to get more creative. Link to comment https://forums.phpfreaks.com/topic/156053-no-images-showing-up/#findComment-821550 Share on other sites More sharing options...
guest1234 Posted April 29, 2009 Author Share Posted April 29, 2009 ok so i did what you said and now something shows up on the screen but not what i want if you go to costawurks.com/filetest.php you will see. That is the same problem i got before and if you go to source code and look this is what it shows: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>test</title> <link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" /> <script type="text/javascript" src="js/prototype.js"></script> <script type="text/javascript" src="js/scriptaculous.js?load=effects"></script> <script type="text/javascript" src="js/lightbox.js"></script> </head> <body> <a href='../public_html/images/banner_thumbnail/../public_html/images/banner_thumbnail/costawurksbanner.jpg' rel='lightbox[roadtrip]' title= ' '><img src='../public_html/images/banner/../public_html/images/banner/CostawurksChristmasbanner24.jpg' border='0'></a> <a href='../public_html/images/banner_thumbnail/../public_html/images/banner_thumbnail/costawurksbanner2.jpg' rel='lightbox[roadtrip]' title= ' '><img src='../public_html/images/banner/../public_html/images/banner/Mercedesbanner2.jpg' border='0'></a> <a href='../public_html/images/banner_thumbnail/../public_html/images/banner_thumbnail/costawurkschristmasbanner.jpg' rel='lightbox[roadtrip]' title= ' '><img src='../public_html/images/banner/../public_html/images/banner/cloudbanner.jpg' border='0'></a> <a href='../public_html/images/banner_thumbnail/../public_html/images/banner_thumbnail/crashbandicootbanner.jpg' rel='lightbox[roadtrip]' title= ' '><img src='../public_html/images/banner/../public_html/images/banner/costabanner2.jpg' border='0'></a> <a href='../public_html/images/banner_thumbnail/../public_html/images/banner_thumbnail/crisisbanner.jpg' rel='lightbox[roadtrip]' title= ' '><img src='../public_html/images/banner/../public_html/images/banner/costawurksbanner.jpg' border='0'></a> <a href='../public_html/images/banner_thumbnail/../public_html/images/banner_thumbnail/frannybanner.jpg' rel='lightbox[roadtrip]' title= ' '><img src='../public_html/images/banner/../public_html/images/banner/crashbandicootbanner.jpg' border='0'></a> <a href='../public_html/images/banner_thumbnail/../public_html/images/banner_thumbnail/gearsofwarbanner.jpg' rel='lightbox[roadtrip]' title= ' '><img src='../public_html/images/banner/../public_html/images/banner/frannybanner.jpg' border='0'></a> <a href='../public_html/images/banner_thumbnail/../public_html/images/banner_thumbnail/goobbanner.jpg' rel='lightbox[roadtrip]' title= ' '><img src='../public_html/images/banner/../public_html/images/banner/goobbanner.jpg' border='0'></a> <a href='../public_html/images/banner_thumbnail/../public_html/images/banner_thumbnail/gotenksbanner.jpg' rel='lightbox[roadtrip]' title= ' '><img src='../public_html/images/banner/../public_html/images/banner/mariobanner2.jpg' border='0'></a> <a href='../public_html/images/banner_thumbnail/../public_html/images/banner_thumbnail/mariobanner.jpg' rel='lightbox[roadtrip]' title= ' '><img src='../public_html/images/banner/../public_html/images/banner/megatronbanner.jpg' border='0'></a> <a href='../public_html/images/banner_thumbnail/../public_html/images/banner_thumbnail/mercedesbanner.jpg' rel='lightbox[roadtrip]' title= ' '><img src='../public_html/images/banner/../public_html/images/banner/mercedesbanner224m4.jpg' border='0'></a> <a href='../public_html/images/banner_thumbnail/../public_html/images/banner_thumbnail/mercedesbanner2.jpg' rel='lightbox[roadtrip]' title= ' '><img src='../public_html/images/banner/../public_html/images/banner/optimusprimebanner.jpg' border='0'></a> <a href='../public_html/images/banner_thumbnail/../public_html/images/banner_thumbnail/patrickbanner.jpg' rel='lightbox[roadtrip]' title= ' '><img src='../public_html/images/banner/../public_html/images/banner/ryubanner.jpg' border='0'></a> <a href='../public_html/images/banner_thumbnail/../public_html/images/banner_thumbnail/ryubanner.jpg' rel='lightbox[roadtrip]' title= ' '><img src='../public_html/images/banner/../public_html/images/banner/sonicbanner.jpg' border='0'></a> <a href='../public_html/images/banner_thumbnail/../public_html/images/banner_thumbnail/tekkenbanner.jpg' rel='lightbox[roadtrip]' title= ' '><img src='../public_html/images/banner/../public_html/images/banner/tekkenbanner.jpg' border='0'></a> <a href='../public_html/images/banner_thumbnail/../public_html/images/banner_thumbnail/tekkenbanner2.jpg' rel='lightbox[roadtrip]' title= ' '><img src='../public_html/images/banner/../public_html/images/banner/toohumancopy.jpg' border='0'></a> <a href='../public_html/images/banner_thumbnail/../public_html/images/banner_thumbnail/toohumanbanner.jpg' rel='lightbox[roadtrip]' title= ' '><img src='../public_html/images/banner/../public_html/images/banner/warcraftbanner.jpg' border='0'></a> <a href='../public_html/images/banner_thumbnail/../public_html/images/banner_thumbnail/transformerbanner.jpg' rel='lightbox[roadtrip]' title= ' '><img src='../public_html/images/banner/../public_html/images/banner/warcraftbanner2.jpg' border='0'></a> <a href='../public_html/images/banner_thumbnail/../public_html/images/banner_thumbnail/transformerbanner2.jpg' rel='lightbox[roadtrip]' title= ' '><img src='../public_html/images/banner/../public_html/images/banner/warcraftbannernew.jpg' border='0'></a> </body> </html> now the problem there is that for example ../public_html/images/banner_thumbnail/../public_html/images/banner_thumbnail/transformerbanner2.jpg the problem is that what is underlined should not be there to view the image any ideas? Link to comment https://forums.phpfreaks.com/topic/156053-no-images-showing-up/#findComment-821562 Share on other sites More sharing options...
xtopolis Posted April 29, 2009 Share Posted April 29, 2009 Post your current PHP code, the example code you pasted is different than your example page's HTML output. Link to comment https://forums.phpfreaks.com/topic/156053-no-images-showing-up/#findComment-821565 Share on other sites More sharing options...
guest1234 Posted April 29, 2009 Author Share Posted April 29, 2009 <?php error_reporting(E_ALL); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>test</title> <link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" /> <script type="text/javascript" src="js/prototype.js"></script> <script type="text/javascript" src="js/scriptaculous.js?load=effects"></script> <script type="text/javascript" src="js/lightbox.js"></script> </head> <body> <?php $dir = "../public_html/images/banner_thumbnail/"; $gallery = glob("$dir*.jpg"); sort($gallery); $dir2 = "../public_html/images/banner/"; $gallery2 = glob("$dir2*.jpg"); sort($gallery2); $imgs = array_combine($gallery, $gallery2); foreach($imgs as $k => $v) { $imag = "<a href=' $k . ' rel='lightbox[roadtrip]' title= ' '>"; $thumb = "<img src=' $v . ' border='0'></a>"; echo $imag.$thumb; echo "\n"; } ?> </body> </html> the reason that i put $imag = "<a href=' $k . ' rel='lightbox[roadtrip]' title= ' '>"; $thumb = "<img src=' $v . ' border='0'></a>"; into variables to use lightbox they need to together so i combined them in echo $imag.$thumb; Link to comment https://forums.phpfreaks.com/topic/156053-no-images-showing-up/#findComment-821567 Share on other sites More sharing options...
xtopolis Posted April 29, 2009 Share Posted April 29, 2009 [ foreach($imgs as $k => $v) { $imag = "<a href='$k' rel='lightbox[roadtrip]' title= ' '>"; $thumb = "<img src='$v' border='0'></a>"; echo $imag.$thumb; echo "\n"; } For reference, echoing $imag.$thumb is the same as replacing $imag = and $thumb = with echo. You're just taking an extra step to put it into a variable, the output would be the same. Link to comment https://forums.phpfreaks.com/topic/156053-no-images-showing-up/#findComment-821581 Share on other sites More sharing options...
guest1234 Posted April 29, 2009 Author Share Posted April 29, 2009 ohhh ok thank you so do you have any idea how to fix this problem? ../public_html/images/banner_thumbnail/transformerbanner2.jpg the underlined and bolded part should not be there for the images to work but when i just put ../../images/banner_thumbnail/ i get those errors from before. Link to comment https://forums.phpfreaks.com/topic/156053-no-images-showing-up/#findComment-821584 Share on other sites More sharing options...
xtopolis Posted April 29, 2009 Share Posted April 29, 2009 depends on your directory... i can't really explain it well.. but if your .php page can be seen in the same window as your images folder, than you don't need the "public_html" part at all i think. Link to comment https://forums.phpfreaks.com/topic/156053-no-images-showing-up/#findComment-821667 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.