• [Mod] Random image / Zufallsbild 5 0 5 1
Currently:  

Author Topic: [Mod] Random image / Zufallsbild  (Read 867354 times)

0 Members and 2 Guests are viewing this topic.

Offline External

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: [Mod] Random image / Zufallsbild
« Reply #525 on: October 24, 2008, 05:37:52 PM »
Hi,

I want to publish random picture on my server www.stacho.cz

The gallery is located at gallery.rammstein-europe.com

I get this error:

Code: [Select]
Warning: include() [function.include]: URL file-access is disabled in the server configuration in /pub/stachowa/stacho.cz/web/test/random.php on line 30

Warning: include(http://gallery.rammstein-europe.com/config.php) [function.include]: failed to open stream: no suitable wrapper could be found in /pub/stachowa/stacho.cz/web/test/random.php on line 30

Warning: include() [function.include]: Failed opening 'http://gallery.rammstein-europe.com/config.php' for inclusion (include_path='.:/usr/local/lib/php:/pub/stachowa/stacho.cz/include') in /pub/stachowa/stacho.cz/web/test/random.php on line 30

Warning: include() [function.include]: URL file-access is disabled in the server configuration in /pub/stachowa/stacho.cz/web/test/random.php on line 31

Warning: include(http://gallery.rammstein-europe.com/includes/db_mysql.php) [function.include]: failed to open stream: no suitable wrapper could be found in /pub/stachowa/stacho.cz/web/test/random.php on line 31

Warning: include() [function.include]: Failed opening 'http://gallery.rammstein-europe.com/includes/db_mysql.php' for inclusion (include_path='.:/usr/local/lib/php:/pub/stachowa/stacho.cz/include') in /pub/stachowa/stacho.cz/web/test/random.php on line 31

Warning: include() [function.include]: URL file-access is disabled in the server configuration in /pub/stachowa/stacho.cz/web/test/random.php on line 32

Warning: include(http://gallery.rammstein-europe.com/includes/constants.php) [function.include]: failed to open stream: no suitable wrapper could be found in /pub/stachowa/stacho.cz/web/test/random.php on line 32

Warning: include() [function.include]: Failed opening 'http://gallery.rammstein-europe.com/includes/constants.php' for inclusion (include_path='.:/usr/local/lib/php:/pub/stachowa/stacho.cz/include') in /pub/stachowa/stacho.cz/web/test/random.php on line 32

Fatal error: Class 'Db' not found in /pub/stachowa/stacho.cz/web/test/random.php on line 35

What I did was that i edited only one line in the php file you provide, it looks now like this:

Code: [Select]
define('ROOT_PATH', 'http://gallery.rammstein-europe.com/');

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_media_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'];
$full_src = (is_remote($row['image_media_file'])) ? $row['image_media_file'] : ROOT_PATH.MEDIA_DIR."/".$cat_id."/".$row['image_media_file'];

echo "<a href=\"".ROOT_PATH."details.php?image_id=$image_id\"><img src=\"".$full_src."\" border=\"1\" alt=\"$image_name\"></a><br>\n";
?>


Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [Mod] Random image / Zufallsbild
« Reply #526 on: October 24, 2008, 08:31:27 PM »
Hello and welcome to 4images forum.

You cannot use full internet path in ROOT_PATH. This script must be on the same server as 4images.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Jan-Lukas

  • Addicted member
  • ******
  • Posts: 1.289
    • View Profile
    • Discover the New World of Kindersurprise
Re: [Mod] Random image / Zufallsbild
« Reply #527 on: October 24, 2008, 08:41:22 PM »
versuche mal dieses

define('ROOT_PATH', './');


Harald
Danke Harald




Offline Nicky

  • Administrator
  • 4images Guru
  • *****
  • Posts: 3.195
    • View Profile
Re: [Mod] Random image / Zufallsbild
« Reply #528 on: October 24, 2008, 09:51:57 PM »
Hi External and welcome to the 4images forum

try it so:
random.php (place it there where your 4images config.php is)
define('ROOT_PATH''./');
define('SCRIPT_URL''http://gallery.rammstein-europe.com/');

instead off:
echo "<a href=\"".ROOT_PATH."details.php?image_id=$image_id\"><img src=\"".$full_src."\" border=\"1\" alt=\"$image_name\"></a><br>\n";

use this

print("
document.write('<a href=\""
.SCRIPT_URL."details.php?image_id=$image_id\"><img src=\"".$full_src."\" border=\"1\" alt=\"$image_name\"></a>');
"
);


on www.stacho.cz try to add this into your html
Code: [Select]
<SCRIPT language='JavaScript'  src='http://gallery.rammstein-europe.com/random.php'></SCRIPT>
hope this will work for you
cheers
Nicky
Your first three "must do" before you ask a question ! (© by V@no)
- please read the Forum Rules ...
- please study the FAQ ...
- please try to Search for your answer ...

nicky.net 4 4images
Signature stolen from mawenzi

Offline External

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: [Mod] Random image / Zufallsbild
« Reply #529 on: October 25, 2008, 12:36:27 PM »
Hi Nicky,

I used the code you provided but it is not working yet. Here is the code:

random.php uploaded to root in gallery.rammstein-europe.com:

Code: [Select]
define('ROOT_PATH', './');
define('SCRIPT_URL', 'http://gallery.rammstein-europe.com/');
include(ROOT.'/config.php');
include(ROOT.'/includes/db_mysql.php');
include(ROOT.'/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_media_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'];
$full_src = (is_remote($row['image_media_file'])) ? $row['image_media_file'] : ROOT_PATH.MEDIA_DIR."/".$cat_id."/".$row['image_media_file'];

print("
document.write('<a href=\"".SCRIPT_URL."details.php?image_id=$image_id\"><img src=\"".$full_src."\" border=\"1\" alt=\"$image_name\"></a>');
");
?>

and this index.htm file in test.stacho.cz:

Code: [Select]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=windows-1250">
  <meta name="generator" content="PSPad editor, www.pspad.com">
  <title></title>
  </head>
  <body>
LOL

<SCRIPT language='JavaScript'  src='http://gallery.rammstein-europe.com/random.php'></SCRIPT>
  </body>
</html>

As you can see, test.stacho.cz doesn't show any images.

Offline Jan-Lukas

  • Addicted member
  • ******
  • Posts: 1.289
    • View Profile
    • Discover the New World of Kindersurprise
Re: [Mod] Random image / Zufallsbild
« Reply #530 on: October 25, 2008, 05:11:10 PM »
hab es mal bei mir als Iframe eingebunden, da kommt diese Fehlermeldung


Warning: include(ROOT/config.php) [function.include]: failed to open stream: No such file or directory in /pub/stachowa/rammstein-europe.com/web/gallery/random.php on line 30

Warning: include() [function.include]: Failed opening 'ROOT/config.php' for inclusion (include_path='.:/usr/local/lib/php:/pub/stachowa/rammstein-europe.com/include') in /pub/stachowa/rammstein-europe.com/web/gallery/random.php on line 30

Warning: include(ROOT/includes/db_mysql.php) [function.include]: failed to open stream: No such file or directory in /pub/stachowa/rammstein-europe.com/web/gallery/random.php on line 31

Warning: include() [function.include]: Failed opening 'ROOT/includes/db_mysql.php' for inclusion (include_path='.:/usr/local/lib/php:/pub/stachowa/rammstein-europe.com/include') in /pub/stachowa/rammstein-europe.com/web/gallery/random.php on line 31

Warning: include(ROOT/includes/constants.php) [function.include]: failed to open stream: No such file or directory in /pub/stachowa/rammstein-europe.com/web/gallery/random.php on line 32

Warning: include() [function.include]: Failed opening 'ROOT/includes/constants.php' for inclusion (include_path='.:/usr/local/lib/php:/pub/stachowa/rammstein-europe.com/include') in /pub/stachowa/rammstein-europe.com/web/gallery/random.php on line 32

Fatal error: Class 'Db' not found in /pub/stachowa/rammstein-europe.com/web/gallery/random.php on line 35



Bin jetzt nicht der Profi, aber kann es sein, das man bei deinem Hoster, nicht von ausserhalb auf die DB zugreifen kann ??
Danke Harald




Offline Nicky

  • Administrator
  • 4images Guru
  • *****
  • Posts: 3.195
    • View Profile
Re: [Mod] Random image / Zufallsbild
« Reply #531 on: October 25, 2008, 06:32:52 PM »
hi all..
http://www.siteshot.at/nicky.htm

your examples can't work.. if you don' use correct code like descriped in the MOD file..

ROOT != ROOT_PATH  :roll:  :lol: :P 8)

use EXACT following code:


<?php
define
('ROOT_PATH''./');
define('SCRIPT_URL''http://gallery.rammstein-europe.com/');
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)) ? 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_media_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'];
$full_src = (is_remote($row['image_media_file'])) ? $row['image_media_file'] : SCRIPT_URL.ROOT_PATH.MEDIA_DIR."/".$cat_id."/".$row['image_media_file'];

print(
"
document.write('<a href=\""
.SCRIPT_URL."details.php?image_id=$image_id\"><img src=\"".$full_src."\" border=\"1\" alt=\"$image_name\"></a>');
"
);
?>


Code: [Select]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=windows-1250">
  <meta name="generator" content="PSPad editor, www.pspad.com">
  <title></title>
  </head>
  <body>
LOL

<SCRIPT language='JavaScript'  src='http://gallery.rammstein-europe.com/random.php'></SCRIPT>
  </body>
</html>

[EDIT by V@no]
corrected index.html to avoid confusion ;) their original code was correct.
« Last Edit: October 25, 2008, 09:31:00 PM by V@no »
cheers
Nicky
Your first three "must do" before you ask a question ! (© by V@no)
- please read the Forum Rules ...
- please study the FAQ ...
- please try to Search for your answer ...

nicky.net 4 4images
Signature stolen from mawenzi

Offline Jan-Lukas

  • Addicted member
  • ******
  • Posts: 1.289
    • View Profile
    • Discover the New World of Kindersurprise
Re: [Mod] Random image / Zufallsbild
« Reply #532 on: October 25, 2008, 07:55:18 PM »
Und auch hier heisst es immer "Augen auf beim coden"  :mrgreen:
ist mir auch nicht aufgefallen, aber bin ja auch kein Profi

LG Harald
Danke Harald




Offline Nicky

  • Administrator
  • 4images Guru
  • *****
  • Posts: 3.195
    • View Profile
Re: [Mod] Random image / Zufallsbild
« Reply #533 on: October 25, 2008, 10:16:16 PM »
Quote
[EDIT by V@no]
corrected index.html to avoid confusion ;) their original code was correct.

oha :)
i think i forgot my site inside.
thank you V@no!

Harald,
kein problem.. ich habs auch zufällig gesehen... ;)
cheers
Nicky
Your first three "must do" before you ask a question ! (© by V@no)
- please read the Forum Rules ...
- please study the FAQ ...
- please try to Search for your answer ...

nicky.net 4 4images
Signature stolen from mawenzi

Offline External

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: [Mod] Random image / Zufallsbild
« Reply #534 on: October 26, 2008, 12:00:42 AM »
Thank you very much, I was little bit blind.

One more question...instead of resizing random generated picture by width and height attribute, is it possible to generate random thumbnail instead of full image?

That would safe a lot of traffic (gigabites per day)

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [Mod] Random image / Zufallsbild
« Reply #535 on: October 26, 2008, 12:13:17 AM »
replace image_media_file with image_thumb_file
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline External

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: [Mod] Random image / Zufallsbild
« Reply #536 on: October 26, 2008, 12:22:42 AM »
I replaced it on 4 places in the code, it looks now like this:
Code: [Select]
<?php
define
('ROOT_PATH''./');
define('SCRIPT_URL''http://gallery.rammstein-europe.com/');
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)) ? 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'];
$full_src = (is_remote($row['image_thumb_file'])) ? $row['image_thumb_file'] : SCRIPT_URL.ROOT_PATH.MEDIA_DIR."/".$cat_id."/".$row['image_thumb_file'];

print(
"
document.write('<a href=\""
.SCRIPT_URL."details.php?image_id=$image_id\"><img src=\"".$full_src."\" border=\"1\" alt=\"$image_name\"></a>');
"
);
?>


But somohow it is still displaying original size pictures. Any ideas?

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [Mod] Random image / Zufallsbild
« Reply #537 on: October 26, 2008, 12:37:24 AM »
ops..forgot one more change...
replace MEDIA_DIR with THUMB_DIR
but I must warn you, if image doesn't have thumbnail, it'll show a broken image.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline External

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: [Mod] Random image / Zufallsbild
« Reply #538 on: October 26, 2008, 12:46:54 AM »
Now it is working just excellent. Thanx a lot people!

Offline External

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: [Mod] Random image / Zufallsbild
« Reply #539 on: October 26, 2008, 01:20:20 AM »
OK, the very last thing (I hope :wink: ) is what to do if I want to display 3 images instead of one?

I mean 3 different images. I tried some modification by myself but it was not working