MAMEWorld >> Programming
View all threads Index   Threaded Mode Threaded  

Pages: 1

GatKong
Tetris Mason
Reged: 04/20/07
Posts: 5907
Loc: Sector 9
Send PM


Any php wisemen?
#321718 - 02/09/14 11:22 AM


specifically in a php block of simple portal 2.3.5 in Simple Machines Forum 2.0.7.

I want to display a random image from a folder.


Code:



$dir = 'http://mywebsite.com/random';
$images = glob($dir. '*.{jpg,jpeg,png,gif}', GLOB_BRACE);
$randomImage = $images[array_rand($images)];

echo '';

?>



Huh. The inequality brackets apparently work even when in a code-box... the code that is not displayed is:
inequality-bracket img src="'.$dir.$randomImage.'" width=89 inequality-bracket

Meh. It only displays a missing image placeholder, not unlike the one echoing above .

It's so simple... yet so not working.

Any help?




p.s. I couldn't post this subject line because it says no profanity...
"Any php gurus?"
LOL... what profanity? Is php so bad it's a three letter four-letter-word?

edit: oh...

Edited by Gatinho (02/09/14 11:31 AM)







krick
Get Fuzzy
Reged: 02/09/04
Posts: 4235
Send PM


Re: Any php wisemen? new [Re: GatKong]
#321728 - 02/09/14 06:38 PM


I think that $randomImage already includes your $dir because you included it in your glob() call.

I think your code should be...

echo '{img src="'.$randomImage.'" width=89}'

(replace curly braces with less-than/greater-than)

I believe this will also work...

echo "{img src=\"$randomImage\" width=89}"

(again, replace curly braces with less-than/greater-than)



Try this. After your glob() call, add this line...

print_r($images);

...And look at the output.

Edited by krick (02/09/14 06:45 PM)



GroovyMAME support forum on BYOAC



GatKong
Tetris Mason
Reged: 04/20/07
Posts: 5907
Loc: Sector 9
Send PM


Re: Any php wisemen? new [Re: krick]
#321745 - 02/09/14 11:41 PM



> Try this. After your glob() call, add this line...
>
> print_r($images);
>
> ...And look at the output.

all I get is

Quote:


Array ( )




That's the frustrating part. The directory is correct, and is full of goodies.

:\







krick
Get Fuzzy
Reged: 02/09/04
Posts: 4235
Send PM


Re: Any php wisemen? new [Re: GatKong]
#321746 - 02/09/14 11:54 PM


wait. I see what's wrong.

glob searches the local filesystem, not an HTTP URL.



GroovyMAME support forum on BYOAC



GatKong
Tetris Mason
Reged: 04/20/07
Posts: 5907
Loc: Sector 9
Send PM


Re: Any php wisemen? new [Re: krick]
#321750 - 02/10/14 03:24 AM


> wait. I see what's wrong.
>
> glob searches the local filesystem, not an HTTP URL.

Nailed it! Ah. I knew I had to be overlooking something ridiculously simple.

Changed
$dir = 'http://mywebsite.com/random';
to
$dir = '../random/';

and BINGO! We got random pics!



Thanks krick!






Pages: 1

MAMEWorld >> Programming
View all threads Index   Threaded Mode Threaded  

Extra information Permissions
Moderator:  Pi 
0 registered and 36 anonymous users are browsing this forum.
You cannot start new topics
You cannot reply to topics
HTML is enabled
UBBCode is enabled
Thread views: 2857