Re: [PHP] Dynamically Rename Images
At 10:19 PM -0400 5/2/09, Andrew Hucks wrote: Is it possible to rename images dynamically? Images are nothing more than files. Load in the file, rename it as you want, and save. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Dynamically Rename Images
Thanks, but I solved the problem another way. http://codepad.org/6juIkECZ. On Sun, May 3, 2009 at 3:02 PM, Michael A. Peters mpet...@mac.com wrote: Andrew Hucks wrote: Got this error: Fatal error: Cannot instantiate non-existent class: finfo in place on line 6 You need the pecl-FileInfo module. You can just comment that out that line and the line after it and (assuming all your images are png) change $mime_type = $fi-buffer(file_get_contents($impath)); to $mime_type = 'image/png'; On Sun, May 3, 2009 at 12:58 AM, Michael A. Peters mpet...@mac.com wrote: 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
[PHP] Dynamically Rename Images
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. Is there a way to do this? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Dynamically Rename Images
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