Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Image Display in Detailed Pages

Quote Reply
Image Display in Detailed Pages
Hi There, I'm fairly new to gossamer links so apologies if I ask any stupid questions.

I am trying to get images to show up in my detailed page listings. I have added the fields into the links database and the add form and they show up in the admin fine. What I am having trouble with is:

1. what do I add to my detailed template to get the image to show correctly? I have tried this:

<%if SDE_Photo1%><img src="/Detailed/UserImages/<%SDE_Photo1%>"><%endif%>

and when I view the source code I get this:
<img src="/Detailed/UserImages/IMG_3396.jpg">

but the image actually gets stored here:
/Detailed/UserImages/4/4-IMG_3396.jpg

So, I'm a little confused about how its storing in these directories and how to link to them.

2. when I go to modify a link, the image form fields are blank and the image values are lost when a user updates a listing. How do I change this so that it is similar to the admin where it changes to "view" and has delete check boxes if an image is present?

Many thanks!
Jan
Quote Reply
Re: [aquaman] Image Display in Detailed Pages In reply to
Hi,

It sounds like you need a global :)

First of all, create a new global, called "get_image_url", and put the following code in it;

Code:
sub {

my ($ID,$field,$table) = @_;

$table ||= 'Links';

# make sure a fieldname and ID are provided...
if (!$ID || !$field) { return "You need to define the ID and fieldname."; }

# get the actual path to where the file is/will be saved...
my $schema = $DB->table($table)->cols;
my $path = $schema->{$field}->{'file_save_url'};
$path =~ s,/$,,; # get rid of trailing / at end of $path

my $image_details = $DB->table("$table_Files")->select( { ForeignColName => $field, ForeignColKey => $ID } )->fetchrow_hashref;

my $id = $image_details->{ID};
my $filename = $image_details->{File_Name};
my $file_url = $image_details->{File_URL}; # this is only the URL/folder

my @cut = split //, $id;
my $folderid = $cut[$#cut];

my $url = "$file_url/$folderid/$id-$filename";


$url =~ s|([^\/]+)$|GT::CGI->escape( $1 )|e;

return $url;

}

Then, in your template.. you can call the image with;

<%get_image_url($ID,'SDE_Photo1','Links')%>

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Image Display in Detailed Pages In reply to
Thanks for the post, much appreciated. I tried this out but received the following error message:

Unable to compile 'get_image_url': Global symbol "$table_Files" requires explicit package name at (eval 33) line 15.

If it makes any difference this is Links 3.0.1
Quote Reply
Re: [aquaman] Image Display in Detailed Pages In reply to
Hi,

Sorry.. this line;

my $image_details = $DB->table("$table_Files")->select( { ForeignColName => $field, ForeignColKey => $ID } )->fetchrow_hashref;

..should be;

my $image_details = $DB->table($table."_Files")->select( { ForeignColName => $field, ForeignColKey => $ID } )->fetchrow_hashref;

Hopefully that will sort it :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Image Display in Detailed Pages In reply to
That worked great - thanks for you help!!

Any suggestions on #2:

2. when I go to modify a link, the image form fields are blank and the image values are lost when a user updates a listing. How do I change this so that it is similar to the admin where it changes to a "view" link and has delete check boxes if an image is present?

Last edited by:

aquaman: May 7, 2005, 3:17 PM
Quote Reply
Re: [aquaman] Image Display in Detailed Pages In reply to
Hi,

No problem :)

Regarding point 2, there isn't much you can really do. I tend to use this;

Code:
<input type="file" name="SDE_Photo1">
<%if SDE_Photo1%>
<br/><br/>
Current Image:<img src="<%get_image_url($ID,'SDE_Photo1','Links')%>">
<%endif%>

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!