Return to the Web Authoring Forum | Post a Follow-Up

 o
Random Images

Posted by chuggerguy (My Page) on
Sun, Sep 9, 12 at 14:53


Follow-Up Postings:

 o
RE: Random Images

Rough code of "index.php":




<?php

if ($dh = opendir('./images')) (
$files = array();
while (($file = readdir($dh)) !== false) (
if ($file !== "." && $file !== ".." && $file !== "index.html") (

array_push($files, $file);
)
)
closedir($dh);
)

$index = array_rand($files);
$extension = pathinfo($files[$index]);
$extension = $extension['extension'];

if ( $extension == "jpg" ) (
header("Content-type: image/jpeg");
imagejpeg(imagecreatefromjpeg("images/".$files[$index]));
)

if ( $extension == "png" ) (
header("Content-type: image/png");
imagepng(imagecreatefrompng("images/".$files[$index]));
)

if ( $extension == "gif" ) (
header("Content-type: image/gif");
echo file_get_contents("images/".$files[$index]);
)

if ( $extension == "bmp" ) (
header("Content-type: image/bmp");
imagebmp(imagecreatefrombmp("images/".$files[$index]));
)

?>


Requires a readable image directory in same directory as "index.php" entitled "images".


 o
RE: Random Images

Posting the above resulted in braces being changed to parenthesis. So... one more time:




<?php


if ($dh = opendir('./images')) "
$files = array();
while (($file = readdir($dh)) !== false) "
if ($file !== "." && $file !== ".." && $file !== "index.html") "

array_push($files, $file);
>
>
closedir($dh);
>

$index = array_rand($files);
$extension = pathinfo($files[$index]);
$extension = $extension['extension'];

if ( $extension == "jpg" ) "
header("Content-type: image/jpeg");
imagejpeg(imagecreatefromjpeg("images/".$files[$index]));
>

if ( $extension == "png" ) "
header("Content-type: image/png");
imagepng(imagecreatefrompng("images/".$files[$index]));
>

if ( $extension == "gif" ) "
header("Content-type: image/gif");
echo file_get_contents("images/".$files[$index]);
>

if ( $extension == "bmp" ) "
header("Content-type: image/bmp");
imagebmp(imagecreatefrombmp("images/".$files[$index]));
>

?>





 o
RE: Random Images

Again, posted is not equal to previewed so... one more time:




<?php


if ($dh = opendir('./images')) "
$files = array();
while (($file = readdir($dh)) !== false) "
if ($file !== "." && $file !== ".." && $file !== "index.html") "

array_push($files, $file);
>
>
closedir($dh);
>

$index = array_rand($files);
$extension = pathinfo($files[$index]);
$extension = $extension['extension'];

if ( $extension == "jpg" ) "
header("Content-type: image/jpeg");
imagejpeg(imagecreatefromjpeg("images/".$files[$index]));
>

if ( $extension == "png" ) "
header("Content-type: image/png");
imagepng(imagecreatefrompng("images/".$files[$index]));
>

if ( $extension == "gif" ) "
header("Content-type: image/gif");
echo file_get_contents("images/".$files[$index]);
>

if ( $extension == "bmp" ) "
header("Content-type: image/bmp");
imagebmp(imagecreatefrombmp("images/".$files[$index]));
>

?>





 o
RE: Random Images

Well... the heck with it. :)


 o
RE: Random Images

A simple upload script to place images in the image directory.
Probably rough, I'm no programmer. It seems to work though.


 o
RE: Random Images

Random song:


 o
RE: Random Images

Because of the way "header" works, that opening php tag absolutely has to be on the very first line, very first character.

I kinda knew, but kinda didn't. I just had to debug because I had added a blank line at the top and pushed it one character right to make it easier to do an area screen capture. :)


 o
RE: Random Images


 o
RE: Random Images


 o
RE: Random Images

This post was edited by chuggerguy on Tue, Jan 29, 13 at 18:28


 o
RE: Random Images


 o
RE: Random Images


 o
RE: Random Images

This post was edited by chuggerguy on Sat, Dec 29, 12 at 21:23


 o
RE: Random Images

Vertical bars turn into semi-colons when posted.
: \:
'\'
:
:

This post was edited by chuggerguy on Fri, Dec 28, 12 at 23:42


 o
RE: Random Images


Vertical bar.

&#124;

This post was edited by chuggerguy on Thu, Dec 27, 12 at 20:22


 o
RE: Random Images

Go here.

This post was edited by chuggerguy on Tue, Apr 16, 13 at 19:48


 o
RE: Random Images

This post was edited by chuggerguy on Sun, Jan 13, 13 at 20:19


 o

link in subject?


 o
RE: Random Images

That should probably be guarded against, at least if it works the same for the title of the original post. There would be no way for the average user to even click into the thread, no way to reply, no way it would ever sink. Maybe it wouldn't work like that in the main title, still... I would be afraid to try it to find out. :)

This post was edited by chuggerguy on Thu, Jan 31, 13 at 2:36


 o
Red Subject

Testing red subject line.


 o

Rotating smiley.


 o Post a Follow-Up

Please Note: Only registered members are able to post messages to this forum.

    If you are a member, please log in.

    If you aren't yet a member, join now!


Return to the Web Authoring Forum

Information about Posting

  • You must be logged in to post a message. Once you are logged in, a posting window will appear at the bottom of the messages. If you are not a member, please register for an account.
  • Please review our Rules of Play before posting.
  • Posting is a two-step process. Once you have composed your message, you will be taken to the preview page. You will then have a chance to review your post, make changes and upload photos.
  • After posting your message, you may need to refresh the forum page in order to see it.
  • Before posting copyrighted material, please read about Copyright and Fair Use.
  • We have a strict no-advertising policy!
  • If you would like to practice posting or uploading photos, please visit our Test forum.
  • If you need assistance, please Contact Us and we will be happy to help.


Learn more about in-text links on this page here