Gamingforce Interactive Forums
85239 35211

Go Back   Exploding Garrmondo Weiner Interactive Swiss Army Penis > Garrmondo Network > Help Desk
Register FAQ GFWiki Community Donate Arcade ChocoJournal Calendar

Notices

Welcome to the Exploding Garrmondo Weiner Interactive Swiss Army Penis.
GFF is a community of gaming and music enthusiasts. We have a team of dedicated moderators, constant member-organized activities, and plenty of custom features, including our unique journal system. If this is your first visit, be sure to check out the FAQ or our GFWiki. You will have to register before you can post. Membership is completely free (and gets rid of the pesky advertisement unit underneath this message).


A little html/php help
Reply
 
Thread Tools
Roph
ヽ(ºДº)ノ


Member 63

Level 25.06

Mar 2006


Reply With Quote
Old Oct 14, 2006, 08:11 PM Local time: Oct 15, 2006, 02:11 AM #1 of 5
A little html/php help

So I have a random image archive thing, here.

You just click the image and it loads another, by refreshing the page. Here's how I have everything working currently:

My index.html is this:

Code:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Random Image Archive</title>
</head>
<body style="margin:50px; text-align:center; background-color:#eeeeee;">
<center><h2>Random Image Archive : Click image to show another
</script></h2><br>
<strong>WARNING:</strong> Some of these images are gross, contain nudity or may otherwise be offensive!<br><br>
 <a href="JavaScript:location.reload(true);"><img src="http://i.slyph.org/r/i.php" alt="Click to show another" border="2" /></a>


</body>
</html>
And the php that's embedded image-style is this:

PHP Code:
<?php
// Image folder.
$folder '';

// Extensions.
$exts 'jpg jpeg png gif';

$files = array(); $i = -1// Initialize some variables
if ('' == $folder$folder './';

$handle opendir($folder);
$exts explode(' '$exts);
while (
false !== ($file readdir($handle))) {
    foreach(
$exts as $ext) { // for each extension check the extension
        
if (preg_match('/\.'.$ext.'$/i'$file$test)) { // faster than ereg, case insensitive
            
$files[] = $file// it's good
            
++$i;
            }
        }
    }
closedir($handle); // We're not using it anymore
mt_srand((double)microtime()*1000000); // seed for PHP < 4.2
$rand mt_rand(0$i); // $i was incremented as we went along

header('Location: '.$folder.$files[$rand]); // End
?>
Though I'd like it so, say, you could right click on the displayed image and get the URL of the image instead of the script. If you "visit" the image (example: right-clicking in firefox and selecting View Image), the script processess again and you end up with a real url, though a different image.

My php knowledge is basically non-existant. If not making it work like I described in the above paragraph is possible, maybe I could use the same script to also display a text link underneath or something to the image. Though that would result in multiple calls to the script, which would end up with the image shown not matching with the URL

Sorry if I'm not making any sense ;_;

Jam it back in, in the dark.
Duminas
Something


Member 29

Level 13.21

Mar 2006


Reply With Quote
Old Oct 14, 2006, 08:32 PM Local time: Oct 14, 2006, 05:32 PM #2 of 5
Any particular reason you're trying to keep the random image script and the display page seperate?

This would be a bit easier if they were merged (for example, you could <a href...> the image to the PHP script itself, which would allow right-clicks, and display a link below.

Want me to show you what I mean? I can't really figure any good way with your present setup.

There's nowhere I can't reach.


Need help using an FTP client? Look no further! ««
Roph
ヽ(ºДº)ノ


Member 63

Level 25.06

Mar 2006


Reply With Quote
Old Oct 14, 2006, 09:22 PM Local time: Oct 15, 2006, 03:22 AM #3 of 5
That'd be great =D

And this is just my own stupid way I ended up with something that at least sort of works. I'm pretty much average at html, but a complete newbie at php.

This thing is sticky, and I don't like it. I don't appreciate it.

Last edited by Roph; Oct 14, 2006 at 10:40 PM.
Duminas
Something


Member 29

Level 13.21

Mar 2006


Reply With Quote
Old Oct 15, 2006, 01:13 AM Local time: Oct 14, 2006, 10:13 PM #4 of 5
This is really quickly written, so it's not the best code, but here's an example of how to make it work all in one file. You can name this whatever, it just needs to be parsed as a PHP file. index.php might be good so it'll load by default if you try to get to the images directory (if it does in fact sit in said directory). Heavily commented to try and make it easier for you. If something needs clarification, by all means.

PHP Code:
<?php
# Where are images?  Leave blank to default to working directory.
# It MUST end with a slash if you set something or it will not work!
$img_dir    '';

# What image extensions are allowable?
# Use array( 'value', 'value' ); syntax.
$img_exts    = array('jpg''jpeg''png');

# No more editing is required.
$images        = array();

# Blank directory?  Assume current directory, then.
if ( $img_dir == '' ) {
    
$img_dir './';
}

# Set dirhandle.  If failed, error out.
if(!$dirh opendir($img_dir)){
    die(
"Could not open directory: {$img_dir}");
}

while ( 
false !== ($file readdir($dirh)) ) {
    
# Grab the extension (everything after the last dot).
    
$fext substr($filestrrpos($file'.') + 1);
    
# Don't include the ., .., or any folder as results.
    
if ( $file != '.'  and $file != '..' and !is_dir($file)) {
        
# See if this file's extension is in the img_exts array.
        # This array contains allowed extensions.
        
if ( in_array $fext$img_exts ) ) { 
            
$files[] = $file;
        }
    }
}
closedir($dirh);

# No need to seed since PHP 4.2.0. This takes any image from
# 0 to the highest index in the $files array, then prepends the
# image directory to the name of the file.
$random_image rand(0count($files));
$random_image $img_dir $files[$random_image];

# This is a heredoc--consider it a multilined print(), simply.
print <<<OUTPUT
<html>
<head>
<title>Random Image</title>
</head>
<body>
<p>Click the image below to pick another random one.</p>
<center>
<a href="
{$_SERVER['PHP_SELF']}"><img src="{$random_image}"></a>
OUTPUT;
?>
This is very bad HTML (not even completed), but I wasn't going for that, since it'll show more or less what to do.

As a note, you see the { } braces wrapping $_SERVER['PHP_SELF'] in the last bit? Those make it so PHP won't error out on the print, since it doesn't like quoted array indices in prints for some reason. Wrapping the variable is the same as concatenating it outside of the quote, essentially.

Hopefully that is of help for you.

I am a dolphin, do you want me on your body?


Need help using an FTP client? Look no further! ««

Last edited by Duminas; Oct 15, 2006 at 01:19 AM.
Roph
ヽ(ºДº)ノ


Member 63

Level 25.06

Mar 2006


Reply With Quote
Old Oct 15, 2006, 12:41 PM Local time: Oct 15, 2006, 06:41 PM #5 of 5
Ahh, got everything working fine thanks to your help =D. Much appreciated.

Most amazing jew boots
Reply


Exploding Garrmondo Weiner Interactive Swiss Army Penis > Garrmondo Network > Help Desk > A little html/php help

Forum Jump


All times are GMT -5. The time now is 01:30 AM.


Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2024, vBulletin Solutions, Inc.