[Pro] PHP Background Script

Hello and thanks in advance.

I am currently building a simple site that when refreshed displays a different image as the background. I plan to have a timed refresh as well to advance the page if it isn’t refreshed manually.

To accomplish the background I purchased this php script:
http://codecanyon.net/item/randomimage-class/308103

It seems pretty straightforward to install. However I am having a bit of trouble getting it working. I tried pasting the code they gave me into an html markup item to no avail.
Here is the code the developer says to insert:

<?php include 'random_image/random_image.php'; $randomImage = new RandomImage(); ?>

Any advice would be greatly appreciated.
Thanks


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

It’s a shame that you got this script simply because this is quite easy to do and I’m sure you could find many examples online of how to do it.

Here’s a similar PHP script I wrote a while ago for a project that loads a random JPG from a given directory when the page loads;

<?php
/* Choose a random background image from the 'Backgrounds' gallery */
function random_pic(){
    $dir = 'admin/data/img/gallery/backgrounds';
    $files = glob($dir . '/*.jpg');
    $file = array_rand($files);
    echo( $files[$file] );
}
?>

<img src="<?php random_pic() ?>">

In regard top your issues there may be several reasons why this isn’t working including;

  1. The include command tells the server to add the code from ‘random_image.php’ to the page. If the server can’t find this then the script will fail. Make sure that the ‘random_image.php’ file is uploaded into a directory on the server called ‘random_image’.
  2. I’ve not looked at the documentation for the script but are you meant to place your random images in a certain location on the server or add a line to the script telling it where the images live? It could be that the script can’t locate your image directory.
  3. Lastly is your page running PHP? Does the page end in .php rather than .html and do you know that the server has PHP enabled?

OK so looking at the comments on that page you mentioned it looks like you specify the image location like this;

<?php
include 'random_image/random_image.php';
$randomImage = new RandomImage();
$randomImage->setFolder('relative-path-to/folder');
?>
<img src="<?php  echo $randomImage->show();?>" />

If you are still stuck maybe you can point us towards the documentation you have (if any) for the script and we can see what might need changing.
Regards,
Tim.

On 13 Feb 2015, at 17:30, rhuggins wrote:

It seems pretty straightforward to install. However I am having a bit of trouble getting it working. I tried pasting the code they gave me into an html markup item to no avail.
Here is the code the developer says to insert:

<?php include 'random_image/random_image.php'; $randomImage = new RandomImage(); ?>

Any advice would be greatly appreciated.


Experienced Freeway designer for hire - http://www.freewayactions.com


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi and thank you for the quick reply.

The only documentation provided is here:
http://codecanyon.net/item/randomimage-class/full_screen_preview/308103

My server does support PHP.

The website I’m doing this for is here:
http://coolascii.com/

I would also be happy to do this another way providing I can figure out how to implement it.

My main goal is to have a site that displays a random image from a folder of 3k images as the page background with a timed refresh or a full page click to refresh.

I have figured out everything but the random background.

Thanks again


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

OK, so I can see that you are working on this page as I type this.

The first thing I notice is that your page name is index.html and it should be index.php as I can see the PHP code in the page. You can change this in the Inspector palette in Freeway.

Also change the PHP I supplied you so that the first line points to a folder on your server with the images in it;

function random_pic(){
    $dir = 'myimages';
    $files = glob($dir . '/*.png');
    $file = array_rand($files);
    echo( $files[$file] );
}

Regards,
Tim.

On 13 Feb 2015, at 19:06, rhuggins wrote:

The website I’m doing this for is here:
http://coolascii.com/


Experienced Freeway designer for hire - http://www.freewayactions.com


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Thanks Tim your help is very much appreciated.

I changed my page name to index.php and I also switched out the PHP to the one you supplied. Am I correct to insert this as an HTML markup through Freeway?

<?php function random_pic(){ $dir = 'images'; $files = glob($dir . '/*.png'); $file = array_rand($files); echo( $files[$file] ); } When I carry this out I find the page to be blank now instead of displaying a broken image icon. Any further thoughts would be welcomed. _______________________________________________ freewaytalk mailing list email@hidden Update your subscriptions at: http://freewaytalk.net/person/options

It could be you’ve an illegal character in there somewhere. I sometimes see these if I copy code from a web page or email.

Try this example;
http://www.freewayactions.com/test/php-random-image/php-random-image.zip

Here’s the output for that file showing a random image every time you refresh the page;
http://www.freewayactions.com/test/php-random-image/

The bits that make this work are in Page > HTML Markup and Page > Extended (to place the image into the page background).

If you get stuck feel free to send me a copy of your Freeway file and I’ll take a closer look.
Regards,
Tim.

On 13 Feb 2015, at 20:03, rhuggins wrote:

When I carry this out I find the page to be blank now instead of displaying a broken image icon.


Experienced Freeway designer for hire - http://www.freewayactions.com


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Thanks for all of this. The example page is executed exactly the way I am hoping for. This is great to know it can be done through Freeway.

I took the example file and opened it in Freeway and then output it to my server as a test to confirm I am doing it correctly on the server side in terms of folder organization.

However I am still left with a blank page. When I look at the source it looks very similar to the example page you linked except for the background file.

Any further suggestions?

The other things I plan to do like the auto page refresh and full page link can be done with actions, which is why I’ve held out on putting together the final Freeway file. My goal is to get the random image working correctly first and then finalize those other details. So far I’ve been making a new Freeway file for each attempt, then uploading it to my server through Transmit.

Thank you so much for the help!


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

One other thing - the example file includes the Upload stuff Action on the dummy page.

Is it necessary? Perhaps I am not understanding it correctly? I plan to include around three thousand images and linking them via the Upload stuff Action seems like it may take some time.

Thanks


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

I plan to include around three thousand images

Then Upload Stuff is not the way - just FTP the images to the server.

But why so many? How many visits would it take to see them all?

Sounds like a totally excessive number.

D


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

On 13 Feb 2015, 8:55 pm, DeltaDave wrote:

I plan to include around three thousand images

Then Upload Stuff is not the way - just FTP the images to the server.

But why so many? How many visits would it take to see them all?

Sounds like a totally excessive number.

D

Thanks for the tip.

It has to be three thousand because it is for a science project with a robotic clicker.

The clicker will click through the pages quickly while a camera records it.

The images are already on the server through FTP.
Now we are just trying to get a page to display them at random.

Thanks.


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

The Upload Stuff Action allowed me to provide a complete sample Freeway file without having to remind users to upload a folder full of images to their web server. If your images aren’t already on the server I would suggest using an FTP application to get them there outside of Freeway.

Looking at your page code I can see that the server is serving the PHP file correctly and that the background image style is there too. The only thing that is missing is the random image reference.

Check that the image folder path in the PHP code is correct and that the folder actually exists on the server. Also check that the file extension in the PHP matches (exactly) the file extensions of the images in that folder. Are they .png or .PNG for example?
Regards,
Tim.

On 13 Feb 2015, at 21:34, rhuggins wrote:

Any further suggestions?


FreewayActions.com - Freeware and commercial Actions for Freeway Express & Pro - http://www.freewayactions.com


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

It has to be three thousand because it is for a science project with a robotic clicker.

OK - beyond a normal use case then.

I was concerned that this was a normal html page and that you were overloading your visitors.

What is the purpose of the project? - intrigued.

D


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

It looks like you’ve managed it. Well done.

FreewayActions.com - Freeware and commercial Actions for Freeway Express & Pro - http://www.freewayactions.com


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

It looks like you’ve managed it. Well done.

Just watch your image file sizes - most of these are between 800Kb and 1Mb which makes for a slow page load.

D


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Thank you all tremendously.

The help is very appreciated, and we couldn’t have done it without your generous help.

We will be adding the other functionality early next week.
It seems like it will all go to plan.

You guys are amazing!

Thanks!


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options