Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cfcontent - how many times on one page? 1

Status
Not open for further replies.

tanny

Programmer
Jan 28, 2001
15
AE
Has anybody tried to use cfcontent more than once on a page? I am trying to show a number of thumbnail jpg's (about 10). Filepaths for these thumbnails are retrieved from a database via a query which is used in a cfloop. I set a session variable with the filename in the loop, then go off to another template to perform a cfcontent for the image source.

Problem is that the last filepath returned from the query is used as the filename in cfcontent for all of the thumbnails. I've checked the session variable name before and after using the img src = "index.cfm" template (which is the one that has cfcontent in it), and the session variable is displaying the correct filepath every time.

I'm now wondering if the server waits until the last possible moment to substitute the filepath into the cfcontent tag, thereby only using the last filepath.

Any ideas anybody?
 
I think you're trying to do something that's not quite possible. The <cfcontent> tag specifies the content of the current page. Since a request to a webserver for a CF script returns a single page, there will be one return type and thus only one <cfcontent> will actually set the content of the page. If you're trying to return a page with multiple thumbnails, just return a page with links to the images instead of returning the actual images with <cfcontent>. I think this is what you really want:

<cfloop...
<img src=&quot;#pathToImages#&quot;><p>
</cfloop>

If the pathToImages field contains a path and not a link, you'll need to do some work to replace the &quot;\&quot; (NT,Windows) to a &quot;/&quot; and remove the &quot;D:&quot; or &quot;C:&quot; part as well. IMO, it's better to store a file path, a url, and the file name when storing image locations. That way you can append the file name onto the file path to access it with cffile and you can append the file name onto the url to give the browser a link to the image.

Hope this helps,
GJ
 
First up GunJack, thankyou so much for replying so quickly. Now, your advice is sound and I'm going to try it, but I should let you know what I'm trying to do. Initially I was pointing directly to the url for the img src. However, the users have decreed their images to be in need of security so that hackers can't bypass the system and go straight to them if they know the image's filename.

So... we're not allowing the webserver to list the contents of the directory (btw I'm working off a Solaris box). Indeed the webserver doesn't even know of the existence of this directory (so I can't make the img src a url). Eventually we're going to limit the security of the directory to coldfusion itself and no others.

What I want to check with you is if <cffile> will work with all of the above limitations. What do you think?
 
Hey Tanny,

Sorry I didn't have a chance to respond yesterday but yes, the cffile should do exactly what you want. I think you read my post to Rene's question a few days ago which involved the same thing you're trying to do. I think what I outlined for him will be exactly what you want.

On the page where you display a list of files, you won't need the cffile, just the cfdirectory to get a list of files. Then use cfoutput to display all of the available files with a link to a view page. You'll need to pass the file name to this via page and make sure you use #urlencodedformat()# around the name so any special characters are properly esacped. On the view page, you'll do your authentication and then use <cfcontent> to read and return the image. You actually won't need cffile now that I think about it as cfcontent can read a file in by itself.

If you have any problems, just post the pertinent code and I or someone else can help,
GJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top