Advanced search  

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Pages: [1]   Go Down

Author Topic: getting pic info from pid  (Read 8242 times)

0 Members and 1 Guest are viewing this topic.

grantson

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 35
getting pic info from pid
« on: June 24, 2010, 11:59:44 am »

Been reading the documentation & searching the board and through the core files all morning trying to find out how the array $Current_pic_data is populated

If i pass the pid in a url to another page within my site how do i then use the pid to gather the rest of the pic info

Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Logged

grantson

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 35
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: getting pic info from pid
« Reply #3 on: June 24, 2010, 01:22:08 pm »

If i pass the pid in a url to another page within my site how do i then use the pid to gather the rest of the pic info
With a simple SQL query like
Code: [Select]
SELECT * FROM cpg15x_pictures WHERE pid = $pid
Logged

grantson

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 35
Re: getting pic info from pid
« Reply #4 on: June 24, 2010, 01:45:15 pm »

yes but how do I construct the database query the sql statement goes into

i assume there are functions within the include files which query the db meaning i dont need to set up the database connection from scratch
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: getting pic info from pid
« Reply #5 on: June 24, 2010, 02:23:14 pm »

Code: [Select]
/**
 * cpg_db_connect()
 *
 * Connect to the database
 **/

function cpg_db_connect()
{
    global $CONFIG;

    $result = @mysql_connect($CONFIG['dbserver'], $CONFIG['dbuser'], $CONFIG['dbpass']);

    if (!$result) {
        return false;
    }

    if (!mysql_select_db($CONFIG['dbname'])) {
        return false;
    }

    return $result;
}

The database settings are stored in include/config.inc.php.
Logged

grantson

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 35
Re: getting pic info from pid
« Reply #6 on: June 24, 2010, 03:09:27 pm »

not quite what i meant but a nudge in the right direction thanks andre


Code: [Select]
$result= cpg_db_query("SELECT `pid`, `filepath`, `filename`, `title`, `caption`, `keywords` FROM {$CONFIG['TABLE_PICTURES']}  WHERE pid='$pid'");
$PIC_DATA = mysql_fetch_array($result) or die(mysql_error());

but when i load the page after adding the query nothing happens,
no errors, no visable page source just a completly blank page
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: getting pic info from pid
« Reply #7 on: June 24, 2010, 03:26:04 pm »

Hard to say what went wrong, if you past only that code snippet.

I don't know how cpg_db_query is set in your code.
I don't know how $CONFIG['TABLE_PICTURES'] is set in your code.
I don't know how $pid is set in your code.
I don't know if a connection to the database already exists.

I don't know why you don't want to establish the database connection with standard PHP functions.
Logged

grantson

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 35
Re: getting pic info from pid
« Reply #8 on: June 24, 2010, 03:44:47 pm »

I don't know why you don't want to establish the database connection with standard PHP functions.

Sorry i think i am confusing both of us here

I have a link to a page in www.mysite.com/gallery/metapage.php?pid=x

when metapage.php loads i want to get the pid from the url then use the functions defined in the copermine include files as they are in other pages

Code: [Select]
<?php

define
('IN_COPPERMINE'true);

require(
'include/init.inc.php');

$pid$_GET['pid'];

$resultcpg_db_query("SELECT `pid`, `filepath`, `filename`, `title`, `caption`, `keywords` FROM {$CONFIG['TABLE_PICTURES']} WHERE pid='$pid'");
$PIC_DATA mysql_fetch_assoc($result) or die(mysql_error());

$PIC_DATA['url']="{$CONFIG['site_url']}albums{$PIC_DATA['filepath']}{$PIC_DATA['filename']}";

$pgTitle="{$PIC_DATA['title']}";
$pgDesc="blah";
$thumbUrl str_replace('normal''thumb'$PIC_DATA['url']);
$redirectUrl="{$CONFIG['site_url']}displayimage.php?pid={PIC_DATA['pid']}";
?>

as i say I was originally hoping there was a function somewhere in the function list that populated the array $current_pic_data[] which is used in displayimage.php etc but have been unable to find it
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: getting pic info from pid
« Reply #9 on: June 25, 2010, 08:31:32 am »

Nice to know that your custom page is running in the context of Coppermine ::)

Code: [Select]
$pid= $_GET['pid'];
See: http://documentation.coppermine-gallery.net/en/dev_superglobals.htm
Logged

grantson

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 35
Re: getting pic info from pid
« Reply #10 on: June 25, 2010, 11:26:25 am »

Thanks Andre, after the initial confusion its now all working

final code looks something like this

Code: [Select]
<?php

define
('IN_COPPERMINE'true);

require(
'include/init.inc.php');

$pid $superCage->get->getInt('pid');

$resultcpg_db_query("SELECT `pid`, `filepath`, `filename`, `title`, `caption`, `keywords` FROM {$CONFIG['TABLE_PICTURES']} WHERE pid='$pid'");
$PIC_INFO mysql_fetch_assoc($result);
mysql_free_result($result);

$pgTitle="{$PIC_INFO['title']}";
$pgDesc="";
$PIC_INFO['url']="{$CONFIG['site_url']}albums/{$PIC_INFO['filepath']}{$PIC_INFO['filename']}";
$PIC_INFO['thumburl'] = "{$CONFIG['site_url']}albums/{$PIC_INFO['filepath']}thumb_{$PIC_INFO['filename']}";
$PIC_INFO['redirectUrl'] ="{$CONFIG['site_url']}displayimage.php?pid={$PIC_INFO['pid']}";
?>

Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: getting pic info from pid
« Reply #11 on: June 25, 2010, 11:54:11 am »

For security reasons I'd change the query to something like
Code: [Select]
$result = cpg_db_query("SELECT pid, filepath, filename, title, caption, keywords, pwidth, pheight FROM {$CONFIG['TABLE_PICTURES']} AS p WHERE pid='$pid' $FORBIDDEN_SET LIMIT 1");
Logged

grantson

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 35
Re: getting pic info from pid
« Reply #12 on: June 25, 2010, 10:26:25 pm »

Thanks Joachim
changes made :)
Logged
Pages: [1]   Go Up
 

Page created in 0.03 seconds with 20 queries.