Display wildcard image in src

I have a series of photos on a server with a strict naming convention: "uniqueId-readableName.jpg". I do this because my site database currently logs a unique identifier (and some unrelated information), but sometimes people have to look at the file server directly to view photos (via FTP), so it is useful to use a readable name. for instance

001456-War Horse.jpg 003295-Sunshine Daiseys.jpg 129084-Laboring at the farm 2013-08-11.jpg 

Now I'm sure the best option would be to create a database with the full file names, but I just wanted to see if anyone had any ideas that I might have missed. This question is similar to SO , but I have strict naming conventions here - I'm not sure if this opens up any possibilities or not.

I apply this to img , but the same idea can be applied to any file extension (for example, download "789-My Homework.zip" or "123-Family vacation.zip").

As an example of what I'm looking for in Windows Explorer, you can search for a file

 0*.jpg 

and all the following files can be returned

 001456-War Horse.jpg 003295-Sunshine Daiseys.jpg 029084-Laboring at the farm 2013-08-11.jpg 

In my case, the initial part is always unique, so I would like to use something like 001456-*.jpg 001456-War Horse.jpg and return it 001456-War Horse.jpg .

Is there any way to do this on a website?

 <img src="001456-*.jpg" /> 
+4
source share
1 answer

Although this method does not exist, you can still run scripts on the server side to perform the required functions.

For example, in PHP, you can use the built-in commands to view the folder, select all files matching the criterion name like "001456 - *. Jpg", and then depending on the number of records returned select the first file name and paste it into the IMG tag.

Here is an example implementation in PHP:

 $files = array(); $id = "001456"; $files = glob("id-*.jpg"); echo "<img src='$files[0]' />"; //Assuming one file is found for every unique ID. 
+4
source

Source: https://habr.com/ru/post/1498892/


All Articles