| |
kaz Noogle

Joined: 23 Jul 2004 Location: Manchester 93.96 GC$
Items
|
Posted: Fri Jul 23, 2004 3:30 am Post subject: Random php script |
|
|
|
I got the idea from www.cosforums when the banner changes every new page
| Code: |
<?
# Put the SERVER PATH to image directory.
# INCLUDE trailing slash
$dir = "/home/deathqe/public_html/forum/randphotos/";
# Put the HTML PATH to image directory.
# DO NOT include trailing slash
$html_dir = "http://www.death-eater.net/forum/randphotos";
$dir_handle = opendir($dir);
$image_array = array();
# This opens up the image directory, grabs all files with a ".jpg" extension
# and puts them into an array. You can set whatever extension you'd like here.
# Just switch out the .jpg for .gif, etc. If you have more than one extension,
# replace this line with something like this:
# if (($file !=".") && ($file !="..") && (substr($file, -4) == ".jpg") || (substr($file, -4) == ".gif"))) {
# This will pull up all .jpg OR .gifs. If you name all the images you want to pull
# a certain way (example, image-thumb.jpg or image.thumb.jpg) you can do this:
# if (($file !=".") && ($file !="..") && (substr($file, -10) == ".thumb.jpg")) {
# basically you want to put the extension in quotes and then count how many characters
# it is and place that after $file, -
while ($file = readdir($dir_handle)) {
if (($file !=".") && ($file !="..") && (substr($file, -4) == ".jpg")) {
$file_name = "$html_dir/$file";
$image_array[$file_name] = $file_name;
}
}
# sorts the array. For some reason this won't work at all
# unless this is done. Can anyone tell me why?
sort($image_array);
$count = sizeof($image_array);
# trims all the URLs of whitespace and assigns each
# item in the array a number to identify it.
for($i = 0;$i<sizeof($image_array); $i++) {
$image[$j++] = rtrim($image_array[$i]);
}
# assign a random value
$r = rand(0,$count-1);
# get the size of a random image
$size = getimagesize($image[$r]);
$width = $size[0];
$height = $size[1];
$img_src = "<img src=\"$image[$r]\" width=\"$width\" height=\"$height\" alt=\"This is a Random Image\" />";
closedir ($dir_handle);
?>
<html>
<head>
</head>
<body>
<p align="center">
<? echo '$img_src; ?><img border="0" src="file:///C:/Documents%20and%20Settings/Owner/Desktop/banner.gif" width="385" height="140"></p>
</body>
</html> |
But I keep getting a parse error , i dont undertand when i wrote the code and tested on my machine server it was fine _________________
Maybe in the future I might just get that address .. |
|
| Back to top |
|
|
intelliot Site Admin

Joined: 01 May 2004
18653.45 GC$
Items
|
Posted: Fri Jul 23, 2004 3:53 pm Post subject: |
|
|
|
| Make sure you upload it in ASCII mode. |
|
| Back to top |
|
|
kaz Noogle

Joined: 23 Jul 2004 Location: Manchester 93.96 GC$
Items
|
Posted: Sat Jul 24, 2004 10:30 am Post subject: |
|
|
|
i did. i found the problem non the less lol <? $img src ?> i had a " before and not one ending  _________________
Maybe in the future I might just get that address .. |
|
| Back to top |
|
|
tjoyce Junior Googler

Joined: 03 Jul 2004
732.15 GC$
Items
|
|
| Back to top |
|
|
tjoyce Junior Googler

Joined: 03 Jul 2004
732.15 GC$
Items
|
Posted: Sun Jul 25, 2004 8:45 am Post subject: Re: Random php script |
|
|
|
| kaz wrote: | I got the idea from www.cosforums when the banner changes every new page
| Code: |
<?
# Put the SERVER PATH to image directory.
# INCLUDE trailing slash
$dir = "/home/deathqe/public_html/forum/randphotos/";
# Put the HTML PATH to image directory.
# DO NOT include trailing slash
$html_dir = "http://www.death-eater.net/forum/randphotos";
$dir_handle = opendir($dir);
$image_array = array();
# This opens up the image directory, grabs all files with a ".jpg" extension
# and puts them into an array. You can set whatever extension you'd like here.
# Just switch out the .jpg for .gif, etc. If you have more than one extension,
# replace this line with something like this:
# if (($file !=".") && ($file !="..") && (substr($file, -4) == ".jpg") || (substr($file, -4) == ".gif"))) {
# This will pull up all .jpg OR .gifs. If you name all the images you want to pull
# a certain way (example, image-thumb.jpg or image.thumb.jpg) you can do this:
# if (($file !=".") && ($file !="..") && (substr($file, -10) == ".thumb.jpg")) {
# basically you want to put the extension in quotes and then count how many characters
# it is and place that after $file, -
while ($file = readdir($dir_handle)) {
if (($file !=".") && ($file !="..") && (substr($file, -4) == ".jpg")) {
$file_name = "$html_dir/$file";
$image_array[$file_name] = $file_name;
}
}
# sorts the array. For some reason this won't work at all
# unless this is done. Can anyone tell me why?
sort($image_array);
$count = sizeof($image_array);
# trims all the URLs of whitespace and assigns each
# item in the array a number to identify it.
for($i = 0;$i<sizeof($image_array); $i++) {
$image[$j++] = rtrim($image_array[$i]);
}
# assign a random value
$r = rand(0,$count-1);
# get the size of a random image
$size = getimagesize($image[$r]);
$width = $size[0];
$height = $size[1];
$img_src = "<img src=\"$image[$r]\" width=\"$width\" height=\"$height\" alt=\"This is a Random Image\" />";
closedir ($dir_handle);
?>
<html>
<head>
</head>
<body>
<p align="center">
<? echo '$img_src; ?><img border="0" src="file:///C:/Documents%20and%20Settings/Owner/Desktop/banner.gif" width="385" height="140"></p>
</body>
</html> |
But I keep getting a parse error , i dont undertand when i wrote the code and tested on my machine server it was fine |
I would do this:
| Code: |
<?
# Put the SERVER PATH to image directory.
# INCLUDE trailing slash
$dir = "/home/deathqe/public_html/forum/randphotos/";
# Put the HTML PATH to image directory.
# DO NOT include trailing slash
$html_dir = "http://www.death-eater.net/forum/randphotos";
$dir_handle = opendir($dir);
$image_array = array();
# This opens up the image directory, grabs all files with a ".jpg" extension
# and puts them into an array. You can set whatever extension you'd like here.
# Just switch out the .jpg for .gif, etc. If you have more than one extension,
# replace this line with something like this:
# if (($file !=".") && ($file !="..") && (substr($file, -4) == ".jpg") || (substr($file, -4) == ".gif")))
# {
# // This will pull up all .jpg OR .gifs. If you name all the images you want to pull
# // a certain way (example, image-thumb.jpg or image.thumb.jpg) you can do this:
# if (($file !=".") && ($file !="..") && (substr($file, -10) == ".thumb.jpg"))
# {
# // basically you want to put the extension in quotes and then count how many characters
# // it is and place that after $file, -
while ($file = readdir($dir_handle))
{
if (($file !=".") && ($file !="..") && (substr($file, -4) == ".jpg"))
{
$file_name = "$html_dir/$file";
$image_array[$file_name] = $file_name;
}
}
# sorts the array. For some reason this won't work at all
# unless this is done. Can anyone tell me why?
sort($image_array);
$count = sizeof($image_array);
# trims all the URLs of whitespace and assigns each
# item in the array a number to identify it.
for($i = 0;$i<sizeof($image_array); $i++)
{
$image[$j++] = rtrim($image_array[$i]);
}
# assign a random value
$r = rand(0,$count-1);
# get the size of a random image
$size = getimagesize($image[$r]);
$width = $size[0];
$height = $size[1];
$img_src = "<img src=\"$image[$r]\" width=\"$width\" height=\"$height\" alt=\"This is a Random Image\" />";
closedir ($dir_handle);
?>
<html>
<head>
</head>
<body>
<p align="center">
<? echo '$img_src'; ?><img border="0" src="file:///C:/Documents%20and%20Settings/Owner/Desktop/banner.gif" width="385" height="140"></p>
</body>
</html> |
... Note the for loop and the while statement, etc.
I just think it's more organized and easier to read that way... _________________ Tom Joyce
tomjoyce@gmail.com
http://sharethegmailinvites.blogspot.com/ |
|
| Back to top |
|
|
neno.tu Google Freak

Joined: 10 Oct 2004 Location: Caracas - Venezuela 5951.00 GC$
Items
|
Posted: Mon Oct 11, 2004 8:32 am Post subject: |
|
|
|
I recommed you to get a PHPEditor, that helps a lot
It is like VS.NET or FrontPage...
Try Googling for a PHPEditor, that will fix your little details when programming...
I have made several scripts that didn't work at first for the stupid errors like missing a letter or a ";" or the " in self...
Hahahah programming is so perfectly design for mistakes....
Let me know about the editor
See ya _________________
NenO-tU Freelancer Web Designer and Programmer |
|
| Back to top |
|
|
jahsound Noogle

Joined: 08 Oct 2004 Location: Paris 355.05 GC$
Items
|
Posted: Wed Oct 13, 2004 12:42 am Post subject: |
|
|
|
If you have a MySQL database, you can also insert your pictures (or only their names) into, and after use the rand() function to select one random image on every new page.
| Code: | | SELECT pic_id FROM pictures ORDER BY rand() |
_________________
 |
|
| Back to top |
|
|
Sponsored Links
|
Posted: 5 Dec 2008 9:20 am Post subject: Advertisements |
|
|
|
|
|
|
| Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Host your free forums with Invision Plus.net forum web hosting with your own subdomain.
alexisBlue v1.2 // Theme Created By: Andrew Charron // Icons in Part By: Travis Carden
|
|
|
|
|