4images Forum & Community

4images Issues / Ausgaben => Discussion & Troubleshooting => Topic started by: swifter_uk on March 18, 2003, 02:38:50 AM

Title: Random Image
Post by: swifter_uk on March 18, 2003, 02:38:50 AM
I would like to re-display the random image from my gallery on other pages within a: my forum and b: an independant website, is this possible or am I clutching at straws?

Mike
Title: Random Image
Post by: Neo1 on March 18, 2003, 03:20:29 AM
Look here http://www.4homepages.de/forum/viewtopic.php?t=1020&start=0
I hope this is what you need.
Title: Random Image
Post by: swifter_uk on March 31, 2003, 03:09:36 AM
Quote from: Neo1
Look here http://www.4homepages.de/forum/viewtopic.php?t=1020&start=0
I hope this is what you need.


Need help with this!

 I have downloaded the code:
**/

// http://www.hovegallery.co.uk/Gallery
define('ROOT_PATH', './4images/');

include(ROOT_PATH.'config.php');
include(ROOT_PATH.'includes/db_mysql.php');
include(ROOT_PATH.'includes/constants.php');

$site_db = new Db($db_host, $db_user, $db_password, $db_name);
function is_remote($file_name) {
  return (preg_match('#^https?\\:\\/\\/[a-z0-9\-]+\.([a-z0-9\-]+\.)?[a-z]+#i', $file_name)) ? 1 : 0;
}

$sql = "SELECT COUNT(*) as total_images
        FROM ".IMAGES_TABLE." a, ".CATEGORIES_TABLE." b
        WHERE a.image_active=1
        AND a.cat_id = b.cat_id
        AND b.auth_viewcat=".AUTH_ALL."
        AND b.auth_viewimage=".AUTH_ALL."
        ";
$row = $site_db->query_firstrow($sql);
$total_images = $row['total_images'];

mt_srand((double)microtime() * 1000000);
$number = ($total_images > 1) ? mt_rand(0, $total_images - 1) : 0;

$sql = "SELECT a.image_id, a.cat_id, a.image_name, a.image_active, a.image_thumb_file, a.image_comments
        FROM ".IMAGES_TABLE." a, ".CATEGORIES_TABLE." b
        WHERE a.image_active=1
        AND a.cat_id = b.cat_id
        AND b.auth_viewcat=".AUTH_ALL."
        AND b.auth_viewimage=".AUTH_ALL."
        LIMIT $number, 1";
$row = $site_db->query_firstrow($sql);
$image_id = $row['image_id'];
$cat_id = $row['cat_id'];
$image_name = $row['image_name'];
$image_comments = $row['image_comments'];
$thumb_src = (is_remote($row['image_thumb_file'])) ? $row['image_thumb_file'] : ROOT_PATH.THUMB_DIR."/".$cat_id."/".$row['image_thumb_file'];

echo "<a href=\"".ROOT_PATH."details.php?image_id=$image_id\"><img src=\"".$thumb_src."\" border=\"0\" alt=\"$image_name\"></a><br>\n";
echo "<b>$image_name</b><br>\n";
echo "Comments: $image_comments<br>\n";
?>

But wherever I try to implement it only so far produces errors or displays the code on the page with no image, what am I missing?

Here is where I want random image to display, somewhere within homepage. http://www.hovedogs.co.uk
Title: Random Image
Post by: Neo1 on March 31, 2003, 01:12:14 PM
First of all.......you can only incluse this to a PHP-Page. So if your page is a htm or html .......rename it to *.php and than include.


Quote
// http://www.hovegallery.co.uk/Gallery
define('ROOT_PATH', './4images/');


And this is not right. Try this:
Code: [Select]
define('ROOT_PATH', '../Gallery/');
Title: Random Image
Post by: swifter_uk on April 01, 2003, 03:38:03 AM
Sorry Jan I must be really dim :cry: I cannot get this to work, I have changed html file to php as you said but all I get displayed is the code i entered in the first place!!!!!!!!

If you can help me where i am going wrong I would apreciate it.

Here is the link where I added the code to test:

http://www.rockysracers.co.uk/Random_image.php
Title: Re: Random Image
Post by: V@no on April 01, 2003, 04:04:30 AM
Quote from: swifter_uk
Here is the link where I added the code to test:

http://www.rockysracers.co.uk/Random_image.php

I think u forgot add <?php at the beginning of the file.
Title: Random Image
Post by: swifter_uk on April 01, 2003, 07:02:35 PM
Thanks v@no,

Tried that too, but still cannot make it work, I must be too dumb!! :cry:

Tried loading to another server that I know definately runs php.

http://www.hovedogs.co.uk/Random_image.php but still no joy!!
Title: Random Image
Post by: Neo1 on April 01, 2003, 09:28:57 PM
Please post the full code.
Title: Random Image
Post by: swifter_uk on April 01, 2003, 10:42:19 PM
Quote from: Neo1
Please post the full code.


here it is:

<?php
/**************************************************************************
 *                                                                        *
 *    4images - A Web Based Image Gallery Management System               *
 *    ----------------------------------------------------------------    *
 *                                                                        *
 *             File: random.php                                           *
 *        Copyright: (C) 2002 Jan Sorgalla                                *
 *            Email: jan@4homepages.de                                    *
 *              Web: http://www.4homepages.de                             *
 *    Scriptversion: 1.0 for 4images 1.6.1                                *
 *                                                                        *
 *    Never released without support from: Nicky (http://www.nicky.net)   *
 *                                                                        *
 **************************************************************************
 *                                                                        *
 *    Dieses Script ist KEINE Freeware. Bitte lesen Sie die Lizenz-       *
 *    bedingungen (http://www.4homepages.de/4images/lizenz.php) für       *
 *    weitere Informationen.                                              *
 *    ---------------------------------------------------------------     *
 *    This script is NOT freeware! Please read the Copyright Notice       *
 *    (http://www.4homepages.de/4images/lizenz_e.php) for further         *
 *    information.                                                        *
 *                                                                        *
 *************************************************************************/


// http://www.hovegallery.co.uk/Gallery
define('ROOT_PATH', '../Gallery/');

include(ROOT_PATH.'config.php');
include(ROOT_PATH.'includes/db_mysql.php');
include(ROOT_PATH.'includes/constants.php');

$site_db = new Db($db_host, $db_user, $db_password, $db_name);
function is_remote($file_name) {
  return (preg_match('#^https?\\:\\/\\/[a-z0-9\-]+\.([a-z0-9\-]+\.)?[a-z]+#i', $file_name)) ? 1 : 0;
}

$sql = "SELECT COUNT(*) as total_images
        FROM ".IMAGES_TABLE." a, ".CATEGORIES_TABLE." b
        WHERE a.image_active=1
        AND a.cat_id = b.cat_id
        AND b.auth_viewcat=".AUTH_ALL."
        AND b.auth_viewimage=".AUTH_ALL."
        ";
$row = $site_db->query_firstrow($sql);
$total_images = $row['total_images'];

mt_srand((double)microtime() * 1000000);
$number = ($total_images > 1) ? mt_rand(0, $total_images - 1) : 0;

$sql = "SELECT a.image_id, a.cat_id, a.image_name, a.image_active, a.image_thumb_file, a.image_comments
        FROM ".IMAGES_TABLE." a, ".CATEGORIES_TABLE." b
        WHERE a.image_active=1
        AND a.cat_id = b.cat_id
        AND b.auth_viewcat=".AUTH_ALL."
        AND b.auth_viewimage=".AUTH_ALL."
        LIMIT $number, 1";
$row = $site_db->query_firstrow($sql);
$image_id = $row['image_id'];
$cat_id = $row['cat_id'];
$image_name = $row['image_name'];
$image_comments = $row['image_comments'];
$thumb_src = (is_remote($row['image_thumb_file'])) ? $row['image_thumb_file'] : ROOT_PATH.THUMB_DIR."/".$cat_id."/".$row['image_thumb_file'];

echo "<a href=\"".ROOT_PATH."details.php?image_id=$image_id\"><img src=\"".$thumb_src."\" border=\"0\" alt=\"$image_name\"></a><br>\n";
echo "<b>$image_name</b><br>\n";
echo "Comments: $image_comments<br>\n";
?>
Title: Random Image
Post by: Neo1 on April 01, 2003, 11:01:41 PM
The code is ok. I have copy this to my folder and open it and it works fine:

http://www.terradreams.de/gallery/random1.php


Try to upload your Random_image.php (like it is) to your Gallery Folder and open it in your browser

http://www.hovedogs.co.uk/Gallery/Random_image.php

If it works, you can include it in every PHP-page on your site.
Title: Random Image
Post by: V@no on April 02, 2003, 12:33:20 AM
the problem is in define('ROOT_PATH', '../Gallery/');
since u put your random.php file in root dir on your server, u must use just one dot: define('ROOT_PATH', './Gallery/');
two dots (../) means that one dir behind.
Title: Random Image
Post by: swifter_uk on April 02, 2003, 12:59:18 AM
I think I understand now!!

Will let you know how I get on, thanks for all the help with this...very grateful :D
Title: Random Image
Post by: swifter_uk on April 02, 2003, 01:27:41 AM
One small question...

now I have it working how do I display this random image on the front of my forum, http://www.hovedogs.co.uk/Owners_Forum
Title: Random Image
Post by: V@no on April 02, 2003, 01:44:27 AM
then, use ../
Title: Random Image
Post by: swifter_uk on April 02, 2003, 01:47:07 AM
Sorry I am a total dunce with this. I need something more specific :cry:
Title: Random Image
Post by: Neo1 on April 02, 2003, 01:47:20 AM
I don´t know your forum .....but try to include it to a php-file like index.php or header.php

<?php
include("path to your random image.php");
?>
Title: Random Image
Post by: swifter_uk on April 02, 2003, 03:56:05 AM
All of the forum style sheets are html!! :cry:
Title: Random Image
Post by: V@no on April 02, 2003, 04:25:23 AM
Quote from: swifter_uk
All of the forum style sheets are html!! :cry:

same as 4images ;)
your forum stile based on templates, that means, that those .html file are generated by php. so u still can try to do so, if your forum support PHP includes in the templates it should work.
Title: Random Image
Post by: swifter_uk on April 02, 2003, 04:30:58 AM
seems like you like to keep me in suspense, so how can I add it to my homepage if all stylesheets or whatever are html....?

I really need a "dummy's guide", to this as I have no experience with this format.
Title: Random Image
Post by: V@no on April 02, 2003, 05:14:02 AM
as Neo1 said, try to add into your board template:
Code: [Select]
<?php 
include&#40;"path to your random image.php"&#41;; 
?>

if this wont work, then u'll need do some "core" modifications in the board code...
Title: I Give up!!
Post by: swifter_uk on April 03, 2003, 02:46:08 AM
I give up!! The code works fine as you can see if you follow the link:
But I can't for love nor money get it to re-display on my Forum homepage via html files, despite trying two different servers.

If anyone is willing to try for me perhaps I can give them  Temporary Admin access via PM?

Such a good concept going to waste :cry:

http://www.hovegallery.co.uk/Gallery/Random_image.php
Title: Random Image
Post by: swifter_uk on April 03, 2003, 07:55:24 PM
I have been told access to php includes on my board is denied for security reasons, shame but at least I know I'm not going mad! 8O