You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Ryan Stille <rp...@willconsult.com> on 2003/07/15 17:28:05 UTC

[users@httpd] Configure to send jpg images with HTML around them?

I'd like to change my apache configuration so that when a user clicks on a jpg image (while "browsing" a directory of images) that instead of just sending the foo.jpg directly to the browser, it sends something like <IMG SRC="foo.jpg">.

I need to do it this way because I am trying to read the path to this image via JavaScript from another frame.  Unless it's an actual HTML page, I cannot get at any JS variables in that frame (security thing).

Is this possible?  I've done some google searching for it, but I think this is a rare need and I haven't found anything about it.

I'm running apache 1.3.

Thanks,
-Ryan

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Configure to send jpg images with HTML around them?

Posted by Brian Dessent <br...@dessent.net>.
csebe@fx.ro wrote:

> With or without Apache-generated directory listing, using mod_rewrite seems
> indeed more elegant since no html should be modified to add the
> href="imagewrapper.cgi?..."
> 
> However, this approach might fail if the same images would be *also*
> requested to be displayed inline in some html pages, and not only
> standalone. In this case the cgi program will wrap the image in HTML anyway,
> and some strange things would occur.
> You'd need a mechanism to decide if an image was requested as part of a page
> => don't wrap it, or as standalone => wrap it. I don't think this can be
> done since the browser launches the requests for images perfectly
> independent...
> 
> As said, using mod_rewrite is more elegant, but the final solution depends
> on the OP's setup.

In a crunch, you could always just modify the html source so that images
loaded there have some identifier, e.g. <img
src="/images/foo.gif?inline"> and then modify your rewriting rule to
recognize "?inline" (or whatever) and not do the rewriting.

But that's kind of ugly in that you'd have to go through all the html
code for the whole site and make the change.  Not that perl/sed wouldn't
be happy to assist of course, but still.

Brian

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


RE: [users@httpd] Configure to send jpg images with HTML around them?

Posted by cs...@fx.ro.
> -----Original Message-----
> From: Brian Dessent [mailto:brian@dessent.net]
> Sent: Wednesday, July 16, 2003 3:33 PM
> To: users@httpd.apache.org
> Subject: Re: [users@httpd] Configure to send jpg images with HTML around
> them?
>
>
> csebe@fx.ro wrote:
> >
> > The simplest approach that comes to mind would be to use a simple HTML
> > wrapper server side program (CGI, PHP, etc). This program, let's call it
> > imagewrapper.cgi, should receive the image name as a parameter
> and return it
> > wrapped in some minimal html to the browser like:
> >
> > <html>
> > <body>
> > <img src="foo.jpg">
> > </body>
> > </html>
> >
> > Then you should change all your existent click-able links to
> something like:
> > <a href="imagewrapper.cgi?img=foo.jpg"><a>
>
> I think (not sure) that the original poster wanted this to happen from
> Apache-generated directory listings of files... in which case you'd just
> need to augment the above with a mod_rewrite rule to turn requests
> ending in "\.(jpe?g|gif|png|tiff?|bmp|whatever)" to a call to this CGI.
>
> Brian
>
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>    "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>

With or without Apache-generated directory listing, using mod_rewrite seems
indeed more elegant since no html should be modified to add the
href="imagewrapper.cgi?..."

However, this approach might fail if the same images would be *also*
requested to be displayed inline in some html pages, and not only
standalone. In this case the cgi program will wrap the image in HTML anyway,
and some strange things would occur.
You'd need a mechanism to decide if an image was requested as part of a page
=> don't wrap it, or as standalone => wrap it. I don't think this can be
done since the browser launches the requests for images perfectly
independent...

As said, using mod_rewrite is more elegant, but the final solution depends
on the OP's setup.

Cheers,

Lian Sebe, M.Sc.
Freelance Analyst-Programmer
www.programEz.net


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Configure to send jpg images with HTML around them?

Posted by Brian Dessent <br...@dessent.net>.
csebe@fx.ro wrote:
> 
> The simplest approach that comes to mind would be to use a simple HTML
> wrapper server side program (CGI, PHP, etc). This program, let's call it
> imagewrapper.cgi, should receive the image name as a parameter and return it
> wrapped in some minimal html to the browser like:
> 
> <html>
> <body>
> <img src="foo.jpg">
> </body>
> </html>
> 
> Then you should change all your existent click-able links to something like:
> <a href="imagewrapper.cgi?img=foo.jpg"><a>

I think (not sure) that the original poster wanted this to happen from
Apache-generated directory listings of files... in which case you'd just
need to augment the above with a mod_rewrite rule to turn requests
ending in "\.(jpe?g|gif|png|tiff?|bmp|whatever)" to a call to this CGI.

Brian

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


RE: [users@httpd] Configure to send jpg images with HTML around them?

Posted by cs...@fx.ro.
The simplest approach that comes to mind would be to use a simple HTML
wrapper server side program (CGI, PHP, etc). This program, let's call it
imagewrapper.cgi, should receive the image name as a parameter and return it
wrapped in some minimal html to the browser like:

<html>
<body>
<img src="foo.jpg">
</body>
</html>

Then you should change all your existent click-able links to something like:
<a href="imagewrapper.cgi?img=foo.jpg"><a>

HTH,

Lian Sebe, M.Sc.
Freelance Analyst-Programmer
www.programEz.net

> -----Original Message-----
> From: Ryan Stille [mailto:rps@willconsult.com]
> Sent: Tuesday, July 15, 2003 6:28 PM
> To: users@httpd.apache.org
> Subject: [users@httpd] Configure to send jpg images with HTML around
> them?
>
>
> I'd like to change my apache configuration so that when a user
> clicks on a jpg image (while "browsing" a directory of images)
> that instead of just sending the foo.jpg directly to the browser,
> it sends something like <IMG SRC="foo.jpg">.
>
> I need to do it this way because I am trying to read the path to
> this image via JavaScript from another frame.  Unless it's an
> actual HTML page, I cannot get at any JS variables in that frame
> (security thing).
>
> Is this possible?  I've done some google searching for it, but I
> think this is a rare need and I haven't found anything about it.
>
> I'm running apache 1.3.
>
> Thanks,
> -Ryan
>
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>    "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org