Development of Gallery - Header Content-type for BLOB
Development of Gallery - Header Content-type for BLOB
Hi anyone / everyone,
I'm working on a module for my employer and I've hit a snag involving data coming from a BLOB field:
I currently am storing images as a thumb and full-size image into a table set up as follows:
id - record ID (integer)
name - title for alt tag (varchar 64)
caption - text
thumb - BLOB
image - BLOB
order - display order (integer)
project_id - link to main project table (integer)
I want to, in the admin section, get the content of this record from the database (which I can do no problem) and echo the thumb field based on the id passed in.
I can retrieve data just fine, and if I print the output of that field it will show the usually binary string info for image types within the admin template. The question is, can I actually output the image using the PHP header ("Content-type: image/jpg") approach, and have it not use the template?
I guess what I'm asking is how can I call the appropriate module action file without needing to have the results of that action file render the template XHTML?
I'm working on a module for my employer and I've hit a snag involving data coming from a BLOB field:
I currently am storing images as a thumb and full-size image into a table set up as follows:
id - record ID (integer)
name - title for alt tag (varchar 64)
caption - text
thumb - BLOB
image - BLOB
order - display order (integer)
project_id - link to main project table (integer)
I want to, in the admin section, get the content of this record from the database (which I can do no problem) and echo the thumb field based on the id passed in.
I can retrieve data just fine, and if I print the output of that field it will show the usually binary string info for image types within the admin template. The question is, can I actually output the image using the PHP header ("Content-type: image/jpg") approach, and have it not use the template?
I guess what I'm asking is how can I call the appropriate module action file without needing to have the results of that action file render the template XHTML?
Re: Development of Gallery - Header Content-type for BLOB
Yes this is possible.
I've done this in FEUMailer module.
All you need to do ist to link your moduleaction with the params disable_theme=1 (for backend) and showtemplate=false (for frontend - notice: must be the string 'false' not the boolean value here).
Here is an example how to perform the ouptput:
And this is the link to that action:
I've done this in FEUMailer module.
All you need to do ist to link your moduleaction with the params disable_theme=1 (for backend) and showtemplate=false (for frontend - notice: must be the string 'false' not the boolean value here).
Here is an example how to perform the ouptput:
Code: Select all
$img_file = dirname(__FILE__). DIRECTORY_SEPARATOR .'images'. DIRECTORY_SEPARATOR .'img.gif';
if(file_exists($img_file) && is_readable($img_file)) {
ob_end_clean();
ob_start();
header("Content-Type: image/gif");
header('Content-Disposition: inline; filename=logo.gif');
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
readfile($img_file);
ob_end_flush();
}
exit;
Code: Select all
$imgUrl = $this->CreateLink($id, 'yourActionHere', $returnid, '', array('showtemplate' => 'false', disable_theme=>true) ,'', true, false, '', true, $prettyurl);
echo '<img src="'.$imgUrl.'" />';
Last edited by NaN on Wed Aug 11, 2010 9:49 pm, edited 1 time in total.
Re: Development of Gallery - Header Content-type for BLOB
just a question.. with the gallery module and image handlers like supersizer, just wondering what would the need be to re do the work? Just wondering.. Cheers -Jeremy
Re: Development of Gallery - Header Content-type for BLOB
Hi Nan,
Thanks for the input. I do have one other issue coming up with this now. The admin side version is working great. Displays my thumbnails no problem and I can do everything I need to.
When I try to make a link on the front end though, it is giving me a few problems.
One approach seems to generate the link with & instead of & and this seems to be causing issues. A second one seems to keep trying to pass it into the admin section. A third approach is closer, but tacks on a returnid that causes it to break.
The values I need to pass in are as follows:
action = action.image.php
type = string of thumb or image
image_id = integer value
the closest I could come up with so far was this:
$params = array (
'image_id'=> $row['picture_id'],
'showtemplate' => 'false',
'disable_theme'=>'true'
);
$iamgeLink = $this->CreateLink($id, 'image', 'image', '', $params ,'', true, false, '', false);
and Hi Jeremy,
This is actually supposed to be a gallery integrated in with another component. I'm sure that their are ways to use the components together, but I needed to get something simple cranked out as quickly as I could and this is the first time I'm dealing with CMSMS. I'm more used to working with raw frameworks than open souce CMS systems, so I figured this was a good way to start getting comfortable with under the hood stuff in case I need it more.
Thank you to both of you for replying though. And if anyone else can suggest what I'm doing wrong, I'd greatly appreciate the input.
Thanks for the input. I do have one other issue coming up with this now. The admin side version is working great. Displays my thumbnails no problem and I can do everything I need to.
When I try to make a link on the front end though, it is giving me a few problems.
One approach seems to generate the link with & instead of & and this seems to be causing issues. A second one seems to keep trying to pass it into the admin section. A third approach is closer, but tacks on a returnid that causes it to break.
The values I need to pass in are as follows:
action = action.image.php
type = string of thumb or image
image_id = integer value
the closest I could come up with so far was this:
$params = array (
'image_id'=> $row['picture_id'],
'showtemplate' => 'false',
'disable_theme'=>'true'
);
$iamgeLink = $this->CreateLink($id, 'image', 'image', '', $params ,'', true, false, '', false);
and Hi Jeremy,
This is actually supposed to be a gallery integrated in with another component. I'm sure that their are ways to use the components together, but I needed to get something simple cranked out as quickly as I could and this is the first time I'm dealing with CMSMS. I'm more used to working with raw frameworks than open souce CMS systems, so I figured this was a good way to start getting comfortable with under the hood stuff in case I need it more.
Thank you to both of you for replying though. And if anyone else can suggest what I'm doing wrong, I'd greatly appreciate the input.
Re: Development of Gallery - Header Content-type for BLOB
If this line is a straight copy/paste, there's a typo:
$iamgeLink = $this->CreateLink($id, 'image', 'image', '', $params ,'', true, false, '', false);
Should it be:
$imageLink = $this->CreateLink($id, 'image', 'image', '', $params ,'', true, false, '', false);
$iamgeLink = $this->CreateLink($id, 'image', 'image', '', $params ,'', true, false, '', false);
Should it be:
$imageLink = $this->CreateLink($id, 'image', 'image', '', $params ,'', true, false, '', false);
Re: Development of Gallery - Header Content-type for BLOB
That is a typo I made.... but the real issue is that using the function this way generates the following output:
http://{domainname}/admin/moduleinterface.php?mact=ProjectProfile,mf3dde,image,0&sp_=f91c9d4d&mf3ddeimage_id=5&mf3ddeshowtemplate=false&mf3ddedisable_theme=true
The output that would work is:
http://{domainname}/moduleinterface.php?mact=ProjectProfile,mf3dde,image,0&sp_=f91c9d4d&mf3ddeimage_id=5&mf3ddeshowtemplate=false&mf3ddedisable_theme=true
Any ideas?
http://{domainname}/admin/moduleinterface.php?mact=ProjectProfile,mf3dde,image,0&sp_=f91c9d4d&mf3ddeimage_id=5&mf3ddeshowtemplate=false&mf3ddedisable_theme=true
The output that would work is:
http://{domainname}/moduleinterface.php?mact=ProjectProfile,mf3dde,image,0&sp_=f91c9d4d&mf3ddeimage_id=5&mf3ddeshowtemplate=false&mf3ddedisable_theme=true
Any ideas?
Re: Development of Gallery - Header Content-type for BLOB
Have you tried CreateFrontendLink it has slightly different parameters:
CreateFrontendLink (string $id, string $returnid, string $action, [string $contents = ''], [string $params = array()], [string $warn_message = ''], [boolean $onlyhref = false], [boolean $inline = true], [string $addtext = ''], [ $targetcontentonly = false], [ $prettyurl = ''])
In the News module you can see an example:
$this->CreateFrontendLink($id,$returnid,'default','',$params, '', true));
Nullig
CreateFrontendLink (string $id, string $returnid, string $action, [string $contents = ''], [string $params = array()], [string $warn_message = ''], [boolean $onlyhref = false], [boolean $inline = true], [string $addtext = ''], [ $targetcontentonly = false], [ $prettyurl = ''])
In the News module you can see an example:
$this->CreateFrontendLink($id,$returnid,'default','',$params, '', true));
Nullig
Last edited by Nullig on Thu Aug 12, 2010 5:34 pm, edited 1 time in total.
Re: Development of Gallery - Header Content-type for BLOB
If I do this:
$this->CreateFrontendLink ($id, NULL, 'image', '', $params ,'', true, false, '', false);
Then I end up with:
http://{domainname}/admin/moduleinterface.php?mact=ProjectProfile,mf3dde,image,0&sp_=f91c9d4d&mf3ddeimage_id=5&mf3ddeshowtemplate=false&mf3ddedisable_theme=true
$this->CreateFrontendLink ($id, NULL, 'image', '', $params ,'', true, false, '', false);
Then I end up with:
http://{domainname}/admin/moduleinterface.php?mact=ProjectProfile,mf3dde,image,0&sp_=f91c9d4d&mf3ddeimage_id=5&mf3ddeshowtemplate=false&mf3ddedisable_theme=true
Re: Development of Gallery - Header Content-type for BLOB
Are you trying to do this in the admin part of your module, or the frontend part?
What php files does the module contain?
What php files does the module contain?
Re: Development of Gallery - Header Content-type for BLOB
This particular part is for the front end.
For the front end I only have (at this time) 2 files:
action.default.php
pulls data from MySQL for a project. This includes project name, description and a few other data points, and a picture_id FK. picture_id is the primary key of a record in a table of images linked to this project. So:
project:
id
name
description
picture_id
projectgallery
id
thumb (blob)
image (blob)
name
project_id
Whichever projectgallery.id is set in project.picture_id will have it's thumb pulled and displayed in the action.default.php
Instead of having files in lots of directory structures, I am storing the files to the blobs and want to pull that data and display it using PHP, such as:
myImage.php?id=1
Pulling projectgallery.id of 1's thumb and displaying it using the
header ("Content-type: image/jpg");
print ($row['thumb']);
sort of approach. I am doing this in my admin and it's working great, but for some reason when I try to generate the URL for the front end to display the image, it doesn't seem to generate quite the right link.
-Greg
For the front end I only have (at this time) 2 files:
action.default.php
pulls data from MySQL for a project. This includes project name, description and a few other data points, and a picture_id FK. picture_id is the primary key of a record in a table of images linked to this project. So:
project:
id
name
description
picture_id
projectgallery
id
thumb (blob)
image (blob)
name
project_id
Whichever projectgallery.id is set in project.picture_id will have it's thumb pulled and displayed in the action.default.php
Instead of having files in lots of directory structures, I am storing the files to the blobs and want to pull that data and display it using PHP, such as:
myImage.php?id=1
Pulling projectgallery.id of 1's thumb and displaying it using the
header ("Content-type: image/jpg");
print ($row['thumb']);
sort of approach. I am doing this in my admin and it's working great, but for some reason when I try to generate the URL for the front end to display the image, it doesn't seem to generate quite the right link.
-Greg
Re: Development of Gallery - Header Content-type for BLOB
Ok. I figured that out - silly me, I replaced the $returnid with $return_id originally, and then tried replacing it with NULL thinking that some weird value must be getting passed in.
So my last question is, does every single module need to be called from within a content page or template?
In other words, if I have a portfolio module with a list display of all the projects completed and a detail view for that specific project, do I have to create a web page for each one, and somehow pass in the id of the requested record to view it's details?
Thanks for your help and input everyone... it's greatly appreciated.
-Greg
So my last question is, does every single module need to be called from within a content page or template?
In other words, if I have a portfolio module with a list display of all the projects completed and a detail view for that specific project, do I have to create a web page for each one, and somehow pass in the id of the requested record to view it's details?
Thanks for your help and input everyone... it's greatly appreciated.
-Greg
Re: Development of Gallery - Header Content-type for BLOB
Yes, modules need to be called from a page or template. However, a single page can be used to display all of the records/projects - you don't need a page for each record/project.
Re: Development of Gallery - Header Content-type for BLOB
To replace the & what about this: str_replace('&', '&', $this->CreateLink(...)); ?