Hello guys. i got this code of a friend who found it somewhere. it rotates images on my site randomly each time it's reloaded. i was wondering if someone could help me out here, i wanna display the image name under the image shown, so for example when someone updates the page and the script chooses an image let's say "justme.jpg" i want it to display under the image the name of the file, wich then is "justme.jpg". wich variable keeps the filename in this script ? $img = null; if (substr($folder,-1) != '/') { $folder = $folder.'/'; } if (isset($_GET['img'])) { $imageInfo = pathinfo($_GET['img']); if ( isset( $extList[ strtolower( $imageInfo['extension'] ) ] ) && file_exists( $folder.$imageInfo['basename'] ) ) { $img = $folder.$imageInfo['basename']; } } else { $fileList = array(); $handle = opendir($folder); while ( false !== ( $file = readdir($handle) ) ) { $file_info = pathinfo($file); if ( isset( $extList[ strtolower( $file_info['extension'] ) ] ) ) { $fileList[] = $file; } } closedir($handle); if (count($fileList) > 0) { $imageNumber = time() % count($fileList); $img = $folder.$fileList[$imageNumber]; } } if ($img!=null) { $imageInfo = pathinfo($img); $contentType = 'Content-type: '.$extList[ $imageInfo['extension'] ]; header ($contentType); readfile($img); } else { if ( function_exists('imagecreate') ) { header ("Content-type: image/png"); $im = @imagecreate (100, 100) or die ("Cannot initialize new GD image stream"); $background_color = imagecolorallocate ($im, 255, 255, 255); $text_color = imagecolorallocate ($im, 0,0,0); imagestring ($im, 2, 5, 5, "IMAGE ERROR", $text_color); imagepng ($im); imagedestroy($im); } } ?> PHP:
No, $_GET['img] doesn't contain it. The name is in $imageInfo['basename'] . You could print it by putting <?php echo $imageInfo['basename']; ?> Echoing $_GET['img'] .. prints out entirew path .. sokmething like /foldername/filename.jpg.
Try out and tell if the solution worked Btw, I too have to thank you coz, I came to know about Pathinfo funtion of PHP by looking at your code .
question, can this be implented in the code above so that it displays this each time the script chooses an image? right now the script is in rotate.php and my mainpage is index.php where i have <img src="http://example.com/rotate.php"> so just putting the ecco in my index file wont work :/
I don't think, the script works that way. Its usign readfile to display the contents.. so, I think <img src="http://example.com/rotate.php"> will display some stary characters and image.. somehtign like <img src=" and your image file and "> If you have a sample, show it so that I can udnerstand.
U r giving a wrong link. Its showing some flash and no images Sorry, Goty it.. was assuming u were using image. Edit:Checked it. Yes its dumping binary like I said. In that script its not possible to do that. You need to modify your script in a different way.Rewriting is better IMO
ok thank you. i think i found a way to do it! so i have another question for you. is it possible to somehow strip text from an output somehow? if for example i echo out someting let's say public_html/www/32.swf is it possible to remove "public_html/www/" so only "32.swf" remains ?