IPv4 Fremnet Logo
TOOLS, TINKERINGS & CODE

Appreciate me

Random Image · Mar 13, 20:42 by Shannon Wynter

Ok, one of the most requests I get is a script for random signature images.

The second most frequent request I get is for random avatar images

Well lets cover the first one

As always this script can be downloaded here

Note for internode customers: if you’re using your node space it’s important to chmod 0755 you’ll need to check with your ftp client on how to do this. If you don’t you will get an ‘Internal Server Error’

One tip I can give you tho is to use the console ftp client included with windows to chmod after you’ve uploaded the file.

Example for Internode users

  1. Go Start/Run
  2. Enter: ftp users.on.net
  3. Log in with your username/password
  4. cd /pathtoscript/
  5. lit site chmod 0755 randomimage.php

That should fix your ‘Internal Server Error’

  1. <?php
  2. /* PHP Rotate 1.00
  3.     By Freman
  4. --------------------------------------------------
  5. Due to the large number of requests I get for
  6. this (and similar) script, I'm making it availible
  7. for all to see and use
  8.  
  9. Configuration Options:
  10. $PathToImages = The path to your image files
  11. Example:
  12. $PathToImages = "images/"
  13. */
  14.  
  15. $PathToImages='images/';
  16.  
  17. // !!!!! Don't edit below here or I won't smack you.!!!!!
  18.  
  19. // Open a directory object
  20. $Dir = dir($PathToImages) or die("Oops, it's broken - are you sure you've got the right PathToImages?\n");
  21. // Read the dir
  22. while (false !== ($DirEntry = $Dir->read())) {
  23. // Look for images
  24. if (preg_match('/\.(jpe?g|gif|png)$/',$DirEntry)) {
  25.   // Keep track of the images we've found
  26.   $Images[] = $DirEntry;
  27. }
  28. }
  29.  
  30. // Get a random image
  31. $Image = $Images[array_rand($Images,1)];
  32.  
  33. if ($fp = fopen("$PathToImages/$Image",'rb')) {
  34. // Helps to know how big the file is we want to read
  35. $FileSize = filesize("$PathToImages/$Image");
  36.   
  37. // Get the file extension
  38. preg_match('/\.(jpe?g|gif|png)$/',strtolower($Image),$Match);
  39.  
  40. // Work out what our content type is
  41. if (in_array($Match[1],array('jpg','jpeg'))) {
  42.   $ContentType = 'image/jpeg';
  43. } elseif (in_array($Match[1],array('gif','png'))) {
  44.   $ContentType = 'image/'.$Match[1];
  45. }
  46.  
  47. // Print out some headers to satisfy the browsers
  48. header("Content-type: $ContentType");
  49. header("Content-length: $FileSize");
  50.  
  51. // Print out some headers to keep the random image from being cached
  52. header("Cache-Control: no-cache, must-revalidate");
  53. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  54.  
  55. // Output our image (Long process huh)
  56. print fread($fp,$FileSize);
  57.  
  58. // Always clean up after yourself
  59. fclose($fp);
  60. }
  61. ?>
  62. Download this code: randomimage.php (Downloaded 200 time(s))

Now to make it work as an avatar you need to trick apache into serving up your php script as a jpg/gif or png file due to the way the forums limit the extensions on files.

Best way to use this file is to make it htaccess.txt on your windows machine, upload it, then rename it to .htaccess

  1. RewriteEngine on
  2.  
  3. RewriteRule randomimage.jpg /~<YOUR USERNAME>/<PATH>/randomimage.php [L]
  4. Download this code: htaccess.txt (Downloaded 140 time(s))
Comments

Spam no more - rel=nofollow is active here, spamming my comments will not help your page rank.

  Textile help
---== Copyright Shannon Wynter - All rights reserved - All wrongs avenged ==--- contact