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.
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();
?>
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;
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’.
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.
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();
?>
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.
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;
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
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.
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.
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.