Andrew Hucks wrote:
Is it possible to rename images dynamically?
Say that I had something like image1.png, and I don't want to rename
it on the server. I'm working on an image rotater for a forum that
doesn't allow anything but image files as signatures.
Here's my code so far:
<?php
//LolRotator
//add images. not too hard.
$images = array("image1.png", "image2.png", "image3.png");
//which one do we gets?
$show = rand(0, (count($images)-1));
//i r got u picture.
echo '<img src="'.$images[$show].'"/>';
?>
I used mod_rewrite, which makes it from image.php to image.png. But,
because the files aren't named image.png, it doesn't work. I need to
figure out somethign between lines 8 and 10 to change the file name to
image.png.
Use mod_rewrite so that request for image.png is handled by a script,
image.php
image.php then randomly picks a image file from list, sends the
appropriate image header, and reads the file sending the content to the
browser. IE -
function sendimage($impath) {
// requires fedora rpm : php-pecl-Fileinfo
$fi = new finfo(FILEINFO_MIME);
$mime_type = $fi->buffer(file_get_contents($impath));
$imageOutput = "";
if ($fp = fopen( $impath , 'rb' )) {
while ($l = fgets($fp)) {
$imageOutput .= $l;
}
$outputLen = strlen($imageOutput);
header("Content-Length: $outputLen");
header("Content-type: $mime_type");
print $imageOutput;
} else {
// for whatever reason we failed
die();
}
}
Is there a way to do this?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php