CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Display images with a wildcard * for extention

 



terrykhatri531
User

Aug 4, 2014, 6:52 AM

Post #1 of 11 (1162 views)
Display images with a wildcard * for extention Can't Post

Hi,

How do I display an image in <img> tag with a wildcard i.e. * in extension, I am trying the following it does not work.



<IMG SRC="tmp/$empid.*" WIDTH ="200" HEIGHT="300" ALIGN="Right" BORDER ="10" BORDERCOLOR="#333"/><br>



But if I hardcode the extension it works :



<IMG SRC="tmp/$empid.jpg" WIDTH ="200" HEIGHT="300" ALIGN="Right" BORDER ="10" BORDERCOLOR="#333"/><br>



Many thanks !!

Terry


FishMonger
Veteran / Moderator

Aug 4, 2014, 7:56 AM

Post #2 of 11 (1159 views)
Re: [terrykhatri531] Display images with a wildcard * for extention [In reply to] Can't Post

Each question you ask is an XY problem. http://www.perlmonks.org/?node=xy+problem

What problem are you trying to solve and what makes you think using * like that is going to solve that problem?


(This post was edited by FishMonger on Aug 4, 2014, 7:57 AM)


terrykhatri531
User

Aug 4, 2014, 8:05 AM

Post #3 of 11 (1156 views)
Re: [FishMonger] Display images with a wildcard * for extention [In reply to] Can't Post

Hi Ron,

I think my question is very straightforward :) because I have images with different extensions like gif png jpg etc.

Please tell me if its not possible.

Thanks.

Terry


(This post was edited by terrykhatri531 on Aug 4, 2014, 8:14 AM)


FishMonger
Veteran / Moderator

Aug 4, 2014, 8:22 AM

Post #4 of 11 (1149 views)
Re: [terrykhatri531] Display images with a wildcard * for extention [In reply to] Can't Post


In Reply To
I think my question is very straightforward :) because I have images with different extensions like gif png jpg etc.


Then you're asking the wrong question.

Your question might be straightforward in your mind, but it's taking all of us down the wrong path.


In Reply To
Please tell me if its not possible.


It's not possible to do what you're asking, but it is certainly possible to solve the real problem that you think using the * is supposed to solve. Unfortunately, you haven't told us about that problem.


terrykhatri531
User

Aug 4, 2014, 10:36 AM

Post #5 of 11 (1140 views)
Re: [FishMonger] Display images with a wildcard * for extention [In reply to] Can't Post

Ok, let me try it again.

I need to display images with different extensions like jpg, gif, png etc obviously under an <img> tag, up to know I was hardcoding the extension to jpg but there are some images uploaded with different extensions, therefore I need your assistance to find a way to be able to display images having different extensions.

Thank you !

Terry


Laurent_R
Veteran / Moderator

Aug 4, 2014, 10:46 AM

Post #6 of 11 (1135 views)
Re: [terrykhatri531] Display images with a wildcard * for extention [In reply to] Can't Post

BTW, this is not really a Perl question.

You certainly can't put a wild card (*) like that in HTML. Now, is this static HTML, or is it dynamically created by a script in a programming language such as Perl, JS, PHP or some other? In this case, you should give us the code that generates the HTML so that we can see how it could be adapted.


Zhris
Enthusiast

Aug 4, 2014, 11:17 AM

Post #7 of 11 (1130 views)
Re: [terrykhatri531] Display images with a wildcard * for extention [In reply to] Can't Post

Technically it is possible, but unlikely to be a good solution. You could create a rewrite rule i.e. in .htaccess, which redirects urls that match your wildcard pattern through a Perl script that looks for the first matching file.

You would be better off storing the filename in your database against each employee like you were previously advised.


Laurent_R
Veteran / Moderator

Aug 4, 2014, 11:44 AM

Post #8 of 11 (1126 views)
Re: [Zhris] Display images with a wildcard * for extention [In reply to] Can't Post


In Reply To
You would be better off storing the filename in your database against each employee like you were previously advised.


Yes, or convert all the pictures to a common format/common extension.


FishMonger
Veteran / Moderator

Aug 4, 2014, 2:10 PM

Post #9 of 11 (1119 views)
Re: [Zhris] Display images with a wildcard * for extention [In reply to] Can't Post


Quote
You could create a rewrite rule i.e. in .htaccess, which redirects urls that match your wildcard pattern through a Perl


A url rewrite rule can not parse and modify the html content of an img tag, which is what it would need to do to accomplish what the OP is asking about.


Zhris
Enthusiast

Aug 4, 2014, 3:55 PM

Post #10 of 11 (1106 views)
Re: [FishMonger] Display images with a wildcard * for extention [In reply to] Can't Post

You're absolutely right, but the end result is the same.

The easiest quickfix with pure .htaccess could look something like:


Code
Options +MultiViews 
RewriteEngine On
RewriteRule ^(.+)\.\*$ http://example.com/$1


http://test.massweb.co.uk/image.html


(This post was edited by Zhris on Aug 4, 2014, 3:55 PM)


terrykhatri531
User

Aug 5, 2014, 1:33 AM

Post #11 of 11 (1081 views)
Re: [Zhris] Display images with a wildcard * for extention [In reply to] Can't Post

Wow Chris, that's fantastic !!

Thanks

Terry

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives