What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » Some PHP Help

Pages: (2): « First [ 1 ] 2 » Last »
Some PHP Help
Author: Message:
Val
Senior Member
****

Avatar

Posts: 698
Reputation: 45
30 / Other / Flag
Joined: Jun 2004
O.P. Some PHP Help
Hey guys im a total php newbie so im wondering how to make a script for random images in a dir. Like some people have in the avatars (i.e Chromy ;)) i thinks its easy to make so if someone could please give me kinda tutorial so i can do it myslef and no bother anyone.

Thanks,
ValSpy
Menthix:
Anonymous doesn\'t have a leader.
Anonymous is the leader of ShawnZ.

Max:
True. But deep down, we all know.
ShawnZ is incharge.
he is /b/ in human form.
11-25-2005 03:49 AM
Profile PM Web Find Quote Report
Ash_
Senior Member
****

Avatar

Posts: 638
Reputation: 31
35 / Male / –
Joined: Aug 2004
RE: Some PHP Help
use scan dir to scan for all gif files. (scandir and substr). then load them all into an array get a random namber thats not bigger then count($array); and use that image.

www.php.net to look up those two functions =)

This post was edited on 11-25-2005 at 03:59 AM by Ash_.
[Image: jeansiger5.jpg]
11-25-2005 03:52 AM
Profile PM Find Quote Report
Val
Senior Member
****

Avatar

Posts: 698
Reputation: 45
30 / Other / Flag
Joined: Jun 2004
O.P. RE: Some PHP Help

quote:
Originally posted by Ash_
use scan dir to scan for all gif files. (scandir and substr). then load them all into an array get a random namber thats not bigger then count($array); and use that image.

www.php.bet to look up those two functions =)
www.php.bet? i think its .net anyways i have no clue what you just said after all im a total php newbie
Menthix:
Anonymous doesn\'t have a leader.
Anonymous is the leader of ShawnZ.

Max:
True. But deep down, we all know.
ShawnZ is incharge.
he is /b/ in human form.
11-25-2005 03:56 AM
Profile PM Web Find Quote Report
Ash_
Senior Member
****

Avatar

Posts: 638
Reputation: 31
35 / Male / –
Joined: Aug 2004
RE: Some PHP Help
quote:
Originally posted by ValSpy
quote:
Originally posted by Ash_
use scan dir to scan for all gif files. (scandir and substr). then load them all into an array get a random namber thats not bigger then count($array); and use that image.

www.php.bet to look up those two functions =)
www.php.bet? i think its .net anyways i have no clue what you just said after all im a total php newbie


lol, you aint gonna learn if i give you the code are you?

code:
<?php
$dir    = '/tmp';
$files1 = scandir($dir);

print_r($files1);
?>

that code gets and displays all contents of a folder.

code:
echo substr('abcdef', -1, 1); // f

prints f.

so you could go.

code:
$dir    = '/images';
$files1 = scandir($dir);

for ($x=0;$x<count($files1);$x++){
if (substr($files1[$x], -1, 3) == 'jpg') {
$images[] = $files1[$x];
print_r ($images);
}
}


now all the images in the folder are in the $images array.

now we get a random number.

code:
$num = rand(0, count($files1));

all code.

code:
$dir    = '/images';
$files1 = scandir($dir);

for ($x=0;$x<count($files1);$x++){
if (substr($files1[$x], -1, 3) == 'jpg') {
$images[] = $files1[$x];
print_r ($images);
}
}
$num = rand(0, count($files1));
echo "<img src='$dir/$images[$num]' />


its not the cleanest way to write it but i should work (not at home at the moment)
[/code]
[Image: jeansiger5.jpg]
11-25-2005 04:07 AM
Profile PM Find Quote Report
Val
Senior Member
****

Avatar

Posts: 698
Reputation: 45
30 / Other / Flag
Joined: Jun 2004
O.P. RE: Some PHP Help
thank you, but i should save it as a .php file right?
Menthix:
Anonymous doesn\'t have a leader.
Anonymous is the leader of ShawnZ.

Max:
True. But deep down, we all know.
ShawnZ is incharge.
he is /b/ in human form.
11-25-2005 04:14 AM
Profile PM Web Find Quote Report
Ash_
Senior Member
****

Avatar

Posts: 638
Reputation: 31
35 / Male / –
Joined: Aug 2004
RE: Some PHP Help
yup.
[Image: jeansiger5.jpg]
11-25-2005 04:15 AM
Profile PM Find Quote Report
Val
Senior Member
****

Avatar

Posts: 698
Reputation: 45
30 / Other / Flag
Joined: Jun 2004
O.P. RE: Some PHP Help
quote:
Originally posted by Ash_
yup.

hmm.... whenever i try to do this i get this error:
---------------------------------------
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@valspy.louhabs.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
-----------------------------------
or this one
-----------------------------------

Fatal error: Call to undefined function: scandir() in /home2/louhabs/public_html/valspy/images/random.php on line 3
-----------------------------------
do you know how to solve this?
Menthix:
Anonymous doesn\'t have a leader.
Anonymous is the leader of ShawnZ.

Max:
True. But deep down, we all know.
ShawnZ is incharge.
he is /b/ in human form.
11-25-2005 04:24 AM
Profile PM Web Find Quote Report
Ash_
Senior Member
****

Avatar

Posts: 638
Reputation: 31
35 / Male / –
Joined: Aug 2004
RE: Some PHP Help
what version of php are you running.

create a new file text.php

put in it

code:
echo phpinfo();

[Image: jeansiger5.jpg]
11-25-2005 04:27 AM
Profile PM Find Quote Report
Val
Senior Member
****

Avatar

Posts: 698
Reputation: 45
30 / Other / Flag
Joined: Jun 2004
O.P. RE: Some PHP Help
quote:
Originally posted by Ash_
what version of php are you running.

create a new file text.php

put in it

code:
echo phpinfo();


well i know how to do that, ive made one a while ago here it is: http://valspy.louhabs.com/php.php

version 4.3.10

EDIT: verstion to version, I hate you Lou! :P

This post was edited on 12-29-2005 at 12:37 AM by Val.
Menthix:
Anonymous doesn\'t have a leader.
Anonymous is the leader of ShawnZ.

Max:
True. But deep down, we all know.
ShawnZ is incharge.
he is /b/ in human form.
11-25-2005 04:35 AM
Profile PM Web Find Quote Report
Mike
Elite Member
*****

Avatar
Meet the Spam Family!

Posts: 2795
Reputation: 48
31 / Male / Flag
Joined: Mar 2003
Status: Online
RE: Some PHP Help
I think scandir(); works only for PHP 5...
YouTube closed-captions ripper (also allows you to download videos!)
11-25-2005 12:57 PM
Profile E-Mail PM Web Find Quote Report
Pages: (2): « First [ 1 ] 2 » Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On