Whether it is only theoretical or not can only answer the OP. It is enough if he wants some icons to be animated gifs and your assumption is already wrong. Compression type is also important based on the content.
Yes, you do need a very busy site and I mean very, very busy. I’ve used this technique a few times and the performance impact is almost zero. However:
That is correct, for a directory with a lot of files this is not a good solution - I don’t know the details here but if he kept each icon in a separate directory then there is only one file. For large directories I would simply store the filename with the extension in the database (or any other data store) and the problem would be solved. I think this would be the best solution in this case - if the OP gets the image ID from somewhere then he could also store the image filename in that same somewhere.
images is the name of the directory (as appears in the URL after the domain name) where images are kept. Then in the <img> tag you reference the image file without the extension:
<img src="images/my-icon" alt="">
The rewrite rule successively checks if a file exists with the extensions .jpg, .gif and .png and if it finds one then it is sent to the browser. These checks are only done for URL paths beginning with images/.
If mod_rewrite is available on the server (it often is) then it’s a pretty simple solution and will perform well even if there are many files in the directory (again - you would need an extremely busy site for this technique to be too slow). And the advantage is the server sends the correct mime-type headers depending on the file extension and the images can be kept on the server with their proper file extensions.
I get the same message, even though the image displays just after the message. I also get the same message if I change the glob path to this, with or without the leading slash:
Sorry, I replied to John_Betong before I saw all the newer comments on this thread.
Your suggestion about simply storing file names in a database is a good one. In fact, I just recently started adding some image information to my database - permissions, captions, etc. So it would be easy to add another column featuring image names.
I’ll check out your $foundImageFilename suggestion, too, however, as I have similar projects that I can’t use a database for.
(Wow, who could imagine that a function with a name like “glob” could be so confusing? There must be others who have had a hard time figuring out how it works - I hope. ;))
It’s a little ridiculous how difficult this being made out to be. All you really need is a if/else. If the variant (png) exists use it if it doesn’t use jpg. That’s it, no glob or anything else. 4 lines of code. A conditional with file_exists().
If the only thing that changes is the extension all you need is a conditional. On Windows you need to be using Windows compatible paths. However, those same paths won’t be compatible with Linux. Xamp has a large amount of inconsistencies with Linux. Something that works on xamp might not work on a Linux server and vice versa. This is normally the point I would tell you to use a vm but I recently got reported for telling people how to improve their work flow so what ever.
By “conditional,” you mean an IF/ELSE script, right?
I upgraded to a Mac years ago, so I no longer have to sweat all the Windows stuff. Windows > Mac, FrontPage > Dreamweaver and Microsoft Server > Linux.
Workflow is very important. I do somethings a little backwards to suite my workflow, but it’s worth it in the long run. For example, spreadsheets are SO convenient for organizing data. So I sometimes have to modify my database tables a bit to match to my spreadsheets.
I don’t understand why you’re recommending a VM, though - were you assuming I’m using Windows?
I could have swore I saw something about xamp in this thread. Anyway yes a if/else with file exists to check whether a png exists and if not use the jpg.
But I just discovered the stupid mistake that (I think) has been fouling me up all along. I have my .htaccess file set up so that it only allows URL’s with lower case letters. So that might explain why URL’s with Applications/MAMP aren’t working.
Inexperience breeds incompetence. It is the same for any industry. Which I guess is why some people ask questions here. Not to mention sometimes the poor decisions of others are difficult / not worth correcting.