Hi, I am using the script random image show from the folder but its not showing the image. plz. help me to solve this issue. I am placing the script now . function select_random_file_funny_image($dir) { if (is_dir($dir)) { if ($HD = opendir($dir)) { $files = array(); while (false !== ($file = readdir($HD))) { if (is_file($dir.$file) && $file != basename($_SERVER['PHP_SELF'])) $files[] = $file; } closedir($HD); if (is_array($files)) { shuffle($files); $file = array_pop($files); $picpath = str_replace(".jpg", "j", $file); $picpath = str_replace(".gif", "g", $picpath); echo '<a href=funny-picture-'.$picpath.'.html> <img src="thumb.php?pic='.$dir.$file.'& w=96& h=94" border=0></a>'; }else { echo"";} } } } $image_dir ="fun/pictures/"; select_random_file_funny_image($image_dir); PHP:
Is it showing anything at all, any errors etc... You have a problem here: echo '<a href=funny-picture-'.$picpath.'.html> <img src="thumb.php?pic='.$dir.$file.'& w=96& h=94" border=0></a>'; PHP: 1. It's best to surround attributes around double quotes, like href="blah.html", src="blah.jpg"... 2. There are no such attributes such as "w" and "h" for images, i'm assuming you meant to use width and height here. 3. You have included & twice for some unknown reason, cause they don't seem as though they should be there. 4. You never actually close your SRC link for the image with a quote. I've corrected that below, anyhow, in addition to adding echo statements which will help debug any further errors <? function select_random_file_funny_image($dir) { if (is_dir($dir)) { if ($HD = opendir($dir)) { while (false !== ($file = readdir($HD))) { if (is_file($dir.$file) && $file != basename($_SERVER['PHP_SELF'])){ echo "<h3>The File $file was added to the array</h3>"; $files[] = $file; } } closedir($HD); if (is_array($files)) { shuffle($files); $file = array_pop($files); $picpath = str_replace(".jpg", "j", $file); $picpath = str_replace(".gif", "g", $picpath); echo "<h3>The File is $file and the path is $picpath</h3>"; echo '<a href="funny-picture-'.$picpath.'.html"> <img src="thumb.php?pic='.$dir.$file.'" width="96px" height="94px" /></a>'; } else{ echo "<h1>It Seems the Directory Exists but no Files were Found</h1>"; } } else{ echo "<h1>It seems false was returned when opening the DIR<h1>"; } } else{ echo "<h1>The DIR supplied is no a valid Directory</h1>"; } } $image_dir ="fun/pictures/"; select_random_file_funny_image($image_dir); ?> PHP: This way you are guaranteed an output and can debug step by step. Try that and let me know what the output is.
Thanks to help me to solve this problem. Sorry i was ill , did not reply you. Anyway its show the output in that way. The File fp1.jpg was added to the array The File fp10.jpg was added to the array The File fp11.jpg was added to the array The File fp12.jpg was added to the array The File fp13.jpg was added to the array The File fp14.jpg was added to the array The File fp15.jpg was added to the array The File fp16.jpg was added to the array The File fp17.jpg was added to the array The File fp18.jpg was added to the array The File fp19.jpg was added to the array The File fp2.gif was added to the array The File fp20.jpg was added to the array The File fp21.jpg was added to the array The File fp22.jpg was added to the array The File fp23.jpg was added to the array The File fp24.jpg was added to the array The File fp25.jpg was added to the array The File fp26.jpg was added to the array The File fp27.jpg was added to the array The File fp28.jpg was added to the array The File fp29.jpg was added to the array The File fp3.jpg was added to the array The File fp30.jpg was added to the array The File fp31.jpg was added to the array The File fp32.jpg was added to the array The File fp33.jpg was added to the array The File fp34.jpg was added to the array The File fp35.jpg was added to the array The File fp36.jpg was added to the array The File fp37.jpg was added to the array The File fp38.jpg was added to the array The File fp39.jpg was added to the array The File fp4.jpg was added to the array The File fp40.jpg was added to the array The File fp41.jpg was added to the array The File fp42.jpg was added to the array The File fp43.jpg was added to the array The File fp44.jpg was added to the array The File fp45.jpg was added to the array The File fp46.jpg was added to the array The File fp47.jpg was added to the array The File fp48.jpg was added to the array The File fp49.jpg was added to the array The File fp5.jpg was added to the array The File fp50.jpg was added to the array The File fp51.jpg was added to the array The File fp52.jpg was added to the array The File fp53.jpg was added to the array The File fp6.jpg was added to the array The File fp7.jpg was added to the array The File fp8.jpg was added to the array The File fp9.jpg was added to the array The File Observing Data on Screen.jpg was added to the array The File Sample.jpg was added to the array The File Thumbs.db was added to the array The File is fp52.jpg and the path is fp52j One thing i want to tell you. that this script is working good in my previous server. the problem i have faced when i have changed my server. May be some setting problems also exists. Can you tell me about that. Thanks
show the source generated by the script - in particular, the img src="thumb.php? etc bits. then copy one of them and paste it into a new browser/tab, it would go as: domain/thumb.php?pic=fun/pictures/fp21.jpg - see if it looks anything like this, see if the url works, if thumb.php opens the file ok, what headers it produces and so forth. it may be that it cannot access the folder to pipe the data, things like absolute path and safe mode can do this (change in hosting can cause this) ALSO width="96px" height="94px" /> - do not put px after the values, this is not css. and finally, array_rand() is a better / faster way of getting a file. remove the shuffle($files) then: $file = $files[array_rand($files)];
Dimi thanks to participate . actually this script is working good in my previous server but when i have changed my server then this problem exists. can you tell me about that. Thanks
yes but you need to check it with the valid images, for example: http://www.funadd.com/thumb.php?pic=fun/pictures/fp21.jpg (this breaks) on your live site you have: http://www.funadd.com/thumb.php?pic=fun/pictures/fp3.jpg&w=96&h=94 - breaks. http://www.funadd.com/thumb.php?pic=wallpapers/animal-wallpaper22.jpg&w=96&h=94 - breaks hence, your problem is with thumb.php. incidentally, use header() to set content type to image/jpeg before outputting anything else. http://www.funadd.com/thumb.php?pic=wallpapers/Thumbs.db&w=96&h=94 -> your script should only add the image to the array if the strings gif|jpg|png are found - not .db. all broken images on your homepage:
in funadd.com you can see there was a left baar, today funny picture and today wallpaper. actually in that boxes this script is shown . when you open this site in internet explorer you can see a cross in that box when you click this cross sign the big image you can see that. actually its the same image which show in the box , i am resizing it. so after click the link then it shows the large image. i did not understand why it did not show in that box.
BECAUSE THUMB.PHP IS BROKEN / CAN'T FIND / READ THE IMAGE AS I CLEARLY SHOWED IN PREVIOUS POSTS. please understand that 'it used to work' has no real meaning in IT. good luck to you, one can only do so much to help people that don't want to be helped...