Random Image PHP Scipt Issue
I am using a
PHP random image
script on a site in which I have 2 different images on each
templated page (random images throgh a site). The two images call
to 2 different folders with the random image script in them (to get
2 distinct images). Thus, 2 different random images. My issue is
that it seems that most browsers at some point do not call for a
new image but use what was there in the last page as it is the same
name:
http://ansano.com/asl/images/random/top/random_image.php
or
http://ansano.com/asl/images/random/bottom/random_image.php
Any idea of how to force a browser to call the PHP script? Or
how to change it so it works site wide?
Thanks!!
I've now been sitting looking for this for a while. I don't seem to be able to get it to work.
Do I need to host to a folder first and then to the FTP server after?
I don't seen to be able to find the new page (TEST PAGE) in the folder I used to publish the site to before I went online. Tried searching for it in finder but I don't get any results on (TESTPAGEfiles).
I can see what you are talking bout I only publish to a local folder but I want to publish via the FTP option in iWeb.
Thank you very much for helping me
Similar Messages
-
IWeb random image generator javascript issue
This is the thread I'm curious about See below.
http://discussions.apple.com/thread.jspa?threadID=1552040
I followed these steps and nothing happened. I'm not quite sure if I did everything right. I dragged the images from my iPhoto albums onto the page, sized them, gave them a 0% opacity and laid them all on top of each other.
Then I pulled the HTML Snippet widget onto the page and entered the script as you posted. I entered my file names (only the last part instead of the full address: image.jpg) and sized the snippet.
Nothing happened. I noticed this was an older post. I'm currently using iWeb '09. Is there something different in the newer version??
Any advice would be helpful! Thanks!I've now been sitting looking for this for a while. I don't seem to be able to get it to work.
Do I need to host to a folder first and then to the FTP server after?
I don't seen to be able to find the new page (TEST PAGE) in the folder I used to publish the site to before I went online. Tried searching for it in finder but I don't get any results on (TESTPAGEfiles).
I can see what you are talking bout I only publish to a local folder but I want to publish via the FTP option in iWeb.
Thank you very much for helping me -
Hello everyone,
Im trying to use (for the first time) random images generated
by PHP. I
installed a Technorama extension and then followed thru the
steps to place a
random image in the page, but there is nothing there when I
browse the page.
Please forgive my ignorance, but I have never done any php
stuff before.
And yes, the files are uploaded to my server. (which does
have php enabled).
The practice page I am using is
www.fionahayward.com/interiordesign/practice.php
I have the effect working with javascript on this page
www.fionahayward.com/interiordesign but am trying to use php
incase people
have javascript turned off.
Maybe its something to do with how Ive set up Server
Behaviours or something
(only guessing)
Thanks for listening
Fiona1) create a php file named rotate.php in the folder where the
images are.
2) paste this code (between the [code ] and [/code]
markers... into that file and save it.
[code]
<?php
$folder = '.';
$extList = array();
$extList['gif'] = 'image/gif';
$extList['jpg'] = 'image/jpeg';
$extList['jpeg'] = 'image/jpeg';
$extList['png'] = 'image/png';
// --------------------- END CONFIGURATION
$img = null;
if (substr($folder,-1) != '/') {
$folder = $folder.'/';
if (isset($_GET['img'])) {
$imageInfo = pathinfo($_GET['img']);
if (
isset( $extList[ strtolower( $imageInfo['extension'] ) ] )
file_exists( $folder.$imageInfo['basename'] )
$img = $folder.$imageInfo['basename'];
} else {
$fileList = array();
$handle = opendir($folder);
while ( false !== ( $file = readdir($handle) ) ) {
$file_info = pathinfo($file);
if (
isset( $extList[ strtolower( $file_info['extension'] ) ] )
$fileList[] = $file;
closedir($handle);
if (count($fileList) > 0) {
$imageNumber = time() % count($fileList);
$img = $folder.$fileList[$imageNumber];
if ($img!=null) {
$imageInfo = pathinfo($img);
$contentType = 'Content-type: '.$extList[
$imageInfo['extension'] ];
header ($contentType);
readfile($img);
} else {
if ( function_exists('imagecreate') ) {
header ("Content-type: image/png");
$im = @imagecreate (100, 100)
or die ("Cannot initialize new GD image stream");
$background_color = imagecolorallocate ($im, 255, 255, 255);
$text_color = imagecolorallocate ($im, 0,0,0);
imagestring ($im, 2, 5, 5, "IMAGE ERROR", $text_color);
imagepng ($im);
imagedestroy($im);
?>
[/code]
4) in whichever file you want the random images to appear,
reference the image so:
src="path/to/that/image/folder/rotate.php"
I tend to use root-relative pathing, but that part is up to
you.
NOTE: I've found that random image references are quirky in
IE browsers - they seem to want the image width and height to
display images that are dynamically selected... I've used this
script to display images that are all the same size and groups that
aren't. When the image size is unknown, I use width:100%
height:100% in my css)
email me if you have any issues with using the script. I use
it a lot with WordPress sites, but it isn't a WP only solution.
syncbox AT gmail DOT com (do the obvious)
HTH -
PHP Random Images (Mr. Powers or other PHP Experts)
Hello everyone,
This is the script from David Power's book using arrays and the rand function (Disclosure).
Basically it changes the images randomly on browser load or refresh.
However, I am trying to add an additional, not sure what to call it, a string or another caption for each images.
Instead of this being a caption, it will be a link, so a link will appear under each caption that goes to another page
when it is clicked on for additional info about the image.
I tried adding another caption and adding a like to it but getting syntax error.
Thanks everyone!
Here is the code:
<?php
$images = array(
array('file' => 'image1',
'caption' => 'Caption 1'),
array('file' => 'image2',
'caption' => 'Caption 2'),
$i = rand(0, count($images)-1);
$selectedImage = "graphics/{$images[$i]['file']}.png";
$caption = $images[$i]['caption'];
?>
And here is where the images are written to the page:
<div id="stage">
<img src="<?php echo $selectedImage; ?>" alt="Random image" />
<p id="caption"><?php echo $caption; ?></p>
</div>
Thanks everyone!
WEThanks for the helpful link!
I found the solution to the problem it was very simple and I feel a little stupid asking the question in the first place but, that's how learning works.
We sometimes stumble upon knowledge.
The problem is I was adding the second string outside of the array.
Here is the right way:
array('file' => 'image1',
'caption' => 'Hello!',
'link1' => '<a href="http://www.msnbc.com">Read more</a>',<--Instead of putting the link here
link2' => '<a href="http://www.npr.org">Idea Center</a>'
<-- I was putting the link here out side the array and not properly ending the string.
$i = rand(0, count($images)-1);
$selectedImage = "graphics/{$images[$i]['file']}.png";
$caption = $images[$i]['caption'];
$link1 = $images[$i]['link1'];
$link2 = $images[$i]['link2'];
?>
Output here:
<div id="stage">
<img src="<?php echo $selectedImage; ?>" alt="Random image" />
<p><?php echo $caption; ?></p>
<?php echo $link1; ?>
<?php echo $link2; ?>
</div>
WE -
I am trying to use the PHP random image generator but I don't
know where to specify the size I want all the pictures to come up
in the code. I created a "php" test page and inserted said code
where I want the images to display but they are too large and throw
the entire page off. Is there a way to tell it that all pictures
should be called up at 240(width) x 350(height)? Any help would be
greatly appreciated. The reason I am doing this is because there
are about 200 images (of students) in this folder and coding each
picture seperately is too time consuming.
Regards,
RM (using DW MX2004)Disregard....I figured it out. As it turns out the best
solution would be to have your original pictures saved with the
desired dimensions. I was able to point the PHP to a directory that
contained pictures with said dimensions and it worked like a charm.
regards. -
Using PHP to display semi-random images?
Hello,
I'm looking for help using PHP and MySQL to generate semi-random images on my web site. Here's what I'm trying to do: I have 60 images, but I only want to display 16 at a time (for examlpe http://artisdead.net/antelopegardens.php).
The way I imagine this is, the design has 16 image placeholders. I want Placeholder 1 (the first image) to randomally pull record ID 1, 2, or 3 from the SQL database, while Placeholder 2 pulls record ID 4-6, etc. It's important that one of the first 3 images displays first, while one of the second 3 images displays next, etc.
I've found various ways to randomize all the images, but I'm not understanding how to constrain the randomization the way I'm looking to. Any help would be greatly appreciated. Thanks in advance.Alamo_Melt wrote:
The way I imagine this is, the design has 16 image placeholders. I want Placeholder 1 (the first image) to randomally pull record ID 1, 2, or 3 from the SQL database, while Placeholder 2 pulls record ID 4-6, etc. It's important that one of the first 3 images displays first, while one of the second 3 images displays next, etc.
Before offering a possible solution, I should point out that your plan has a minor flaw. If you display only 16 images, and want the random choice to come from incremental sets of three, the maximum number you can have in your set is 48. The final 12 images will never be selected. For 60 images, you need 20 placeholders. The alternative is to have a total set of 64 images, and make the random choice come from incremental sets of four images.
With that caveat, here's how I would do it. The primary keys of your records might not be consecutive, particularly if records are deleted and new ones added, so it might be a good idea to have a separate column with consecutive numbers from 1 to the the maximum. To select random numbers from incremental groups of three, use the following:
$id = array();
$min = 1;
$max = 3;
for ($i = 0; $i < 16; $i++) {
// generate random number from current set
$id[$i] = mt_rand($min, $max);
// increment the minimum and maximum numbers for the next set
$min += 3;
$max += 3;
// join the selected values as a comma-separated string
$vals = implode(',', $id);
$sql = "SELECT image FROM images WHERE id IN ($vals)";
// excecute the SQL query -
Random images display strong yellow/green cast
system - 24" intel iMac, 3ghz, 2gb, 500bg hd, NVIDIA GeForce 8800 GS with 512MB memory, OS 10.5.4. Just purchased.
System runs fine, and I love the machine. Problem is random images, jpegs, raw, illustrator files, display an awful yellowish tint, both in the preview and when opened in PS or preview. Just random, sometimes a whole folder of images, sometimes just a few. I, of course tested some of the same images on another mac, and they viewed correctly. If I save a copy to the desktop, the icon looks correct, but when opened it looks like puke. Also happens in front row when displaying certain album covers and video trailer art.
Anyone else run into this?
-hHello Double H Media
Welcome to Apple Discussions!
Unfortunately the OP and others appear to have the same issue possibly related to the GeForce 8800 GS, see the following thread!
http://discussions.apple.com/thread.jspa?messageID=7224138�
Dennis -
Hi,
since I updated to Yosemite (but cannot assure it's related or started exactly that moment) I've been experienced a weird issue.
When I open a folder to navigate it, and it's set on "show items as icons", I see all the icons, for just less than a second, replaced by random images.
It's like if while the proper folder/file icon it's loading, that space is temporarily occupied by the impression of another one (or parts of it), coming from my computer. Sometimes is a photo, sometimes another folder icon not related, sometime is the icon of a software.
The picture then goes away (it stays less than a second) and the icon for the file/folder is then the appropriate one.
I have a Macbook Pro 15-inc, mid 2010.
Is it a known issue? If yes, how can I solve, if possible, this?
Hope can be helpful to others too.
Many ThanksFirst off, I do not recommend looking at your time machine while it is running. You can tell if it is running by making sure its menubar icon is shown in Apple menu -> System Preferences -> Time Machine. If the icon is moving, it is running. You can manually backup, which I recommend over automatic backup, as automatic backup can get in your way. Spotlight, if it is indexing (check the menu in the upper right that looks like a magnifying glass), will also slow matters down, and adding things you don't want Spotlight to search to your Apple menu -> System Preferences -> Spotlight -> Privacy pane will help. Note this affects areas you can search in Time Machine as well. If searching content of files is of little interest to you, I find Find Any File much quicker for finding by file name. Backup when you aren't doing anything else, as otherwise, you may find yourself backing up files that haven't had the opportunity to close.
Time Machine also works best if your destination drive is at least twice as capacious as your source drive. Otherwise it is spending a lot of time trying to find places for the archived files, and barely is more archival than a simple clone. -
Random Image not displaying in Live View.
My page is at:
www.andrewjamesartist.co.uk
There's a random image script on the front page.
<img src="randomimages/rotate.php" alt="A Sample Image from the work of Andrew James" />
That's how it is placed in the page.
It shows in preview in browser and it's OK live but it doesn't show in LiveView.
I use a testing server set up with virtual hosts.
MartinMy page is at:
www.andrewjamesartist.co.uk
There's a random image script on the front page.
<img src="randomimages/rotate.php" alt="A Sample Image from the work of Andrew James" />
That's how it is placed in the page.
It shows in preview in browser and it's OK live but it doesn't show in LiveView.
I use a testing server set up with virtual hosts.
Martin -
Randomizing image/text on refresh
Hello. I'm new...quite new to DW and web work, but have a small, general understanding of it. I'm an animator and am in the midst of creating my own portfolio site. I don't understand code, at least uber-extreme code. I'm attempting to have specific quotes on my homepage from clients and would like to have them change, or have a new text/quote appear on refresh or upon a new visit to the site (just so it's not the same one everytime).
Would I need to just render out a .swf file in AE or is there a means of doing this within DW w/o using crazy code? Thanks in advance, AndyHTML has no way to do something like this. You would indeed have to use Flash, or JavaScript, or some server-scripting to accomplish that task.
It's quote easy to do with something like PHP, for example, by declaring a random variable in the page, e.g.,
<?php
$imageVar = rand(1,5) /* this will generate a random number between 1 and 5 */
?>
and then using that random variable in the image's source attribute -
<img src="images/random/image<?php echo $imageVar; ?>.jpg" />
If you are getting the idea that you will have to come to grips with code sooner rather than later, then you are on the right track. DW is very punishing to those who won't take the time to learn the underlying technologies....
If you Google "random image" and "Dreamweaver" you may also be able to find extensions that do the same thing for you (in JavaScript). I would recommend that you visit http://www.projectseven.com and search there - I do know that they have such a thing, and can wholeheartedly endorse their products as being the best of show.... -
Need Random Image Script with Links
I am needing a script for random images on my homepage. I
need the image to have its own link depending on what image is
displayed. I would like a php script (non database) if
possibleSee comments on DW forum about random includes and this
particular markup
shown below.
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com
- Template Triage!
http://www.projectseven.com/go
- DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs,
Tutorials & Resources
http://www.macromedia.com/support/search/
- Macromedia (MM) Technotes
==================
"newhorizonhosting.com" <[email protected]>
wrote in message
news:e29on1$buf$[email protected]..
>I figured it out by doing a random include
>
> <?
> srand(time());
> $random = (rand()%3);
> print("$random");
> require_once("./$random.php");
> ?> -
Need Random Image Script with Link
I am needing a script for random images on my homepage. I
need the image to have its own link depending on what image is
displayed. I would like a php script (non database) if
possibleNot sure about the PHP but there are some good scrips on
www.kaosweaver.com
Paul Whitham
Certified Dreamweaver MX2004 Professional
Adobe Community Expert - Dreamweaver
Valleybiz Internet Design
www.valleybiz.net
"newhorizonhosting.com" <[email protected]>
wrote in message
news:e28rpm$8is$[email protected]..
>I am needing a script for random images on my homepage. I
need the image to
>have its own link depending on what image is displayed. I
would like a php
>script (non database) if possible -
Another random image: empty frames
Hi,
trying to create a Web page, according to the recommendations of the previous threads.
http://www.goldschmiede-blumberg.de/AdobTest/random/randomLink.php
When renewing the page (F5) often enough, one blank frame appears, their image names are changing, however.
Please help me to eliminate this mistake.
Hans-G.Hi,
with this correction in the sense of your advice:
<a href="#"> <img alt="LinkGrafik08-300.jpg" src="images/LinkGrafik08-300.jpg"/> </ a>
I think now it's all ok. I ignored that all images must be named (although all images had been uploaded). Thanks so much, especially for your prompt, fast and professional response.
Hans-G. -
Bridge displaying random image
I have a MacPro with 10.5.2 and CS3. I work mostly in the Horizontal Filmstrip mode and I am having serious issues with previews. I click on a thumbnail and a random image from a completely different folder shows in the large window. Anyone else have this issue? Suggestions? Thanks.
Yes, Scott is right. We either put up with spurious thumbnails or with blurry previews. Obviously the latter is the lesser of the two evils.
After
UNchecking High-quality Previews in Bridge, you need to quit and re-launch Bridge, then painstakingly Purge the Cache for each darned folder, one by one, through the Tools menu in Bridge.
DO NOT use the global Purge Cache command because that one is broken. If you use it, the cache will NOT rebuild properly.
Unfortunately, I've given up all hope of Adobe fixing it, as CS4 is around the corner, a version to which I have no plans to upgrade. :/ -
Suggestions for simple random image script
Would like to randomly display one of five new JPG banner each time page is loaded.
Your experience would be appreciated.
ThanksSince no one replied, I am posting solution I found.for future inquiries.
Simple PHP Random Image Script
This can be done in one line of text directly in your HTML and a collection of images.
The first step is to gather together the images you wish to have randomly rotated.
Change all of their file names to a numerical order, starting with the number 1.
* 1.jpg
* 2.jpg
* 3.jpg
* 4.jpg
Be sure each image has the same extension (either all jpg, png, or gif),
and that there are no gaps in the numbers.
Also, place these images in their own folder to keep everything organized.
Write the Code
In the HTML of your page, insert the following code where you want an image to display:
<img src="path/<?php echo rand(1,n);?>.jpg" alt="Random Image" />
The “rand” operator will display a randomly generated number between 1 and ‘n’.
Change ‘n’ to the total amount of pictures you have arranged numerically
(or the highest numbered picture you have).
In the example above I only have 4 pictures, therefor I would change it to: rand(1,4);
Maybe you are looking for
-
Help with Photoshop Elements 7
Hello, I have Adobe Photoshop Elements 7 running on Windows Vista. It will not open and all my photos are in it. Help Where are the photos stored? Should I reinstall Photoshop Elements 7 if I do will I lose all my photos that are in it. Thanks for
-
Chinese characters in Labview 8
HI, I have a Labview 8 Professional version on Linux. I want to know if Labview 8 professional version supports chinese characters. I want to have chinese characters in my front panel but i dont know how to do it. My linux OS doesnt have any chinese
-
Missing camera attributes with the NI IMAQ for IEEE-1394 driver
I'm using an ORCA-AG and the IEEE-1394 driver. When i look at the camera attributes (either with MAX or the attribtue inquiry vi.) i can see just some of them (brightness, shutter,...). I have tried the ORCA-ER, which has the same attributes, but use
-
All / Experts, Can we use a.invoices in the IN clause of the below query: select a.user_id, count(*) Download from ( select '''' || to_char(replace ( substr(details, 26 , instr( details , '<' , 1,3)-26 ) , ',', ''',''' ) || '''') as invoices , acting
-
hi i have a reqt, i.e, the discount given to customer is restricted for only first 10 sales orders, after it should not. hw can it configured. regards, sai