I am developing a database driven web app. and there is a cell that users can enter any image url or string as input.
is there a function that, image url / string seperation and if it is image, checks for existence.
I need to do that, if a user entered an image url then image is going to show into app (if exists), otherwise if user entered a string (message) then message is going to placed into app.
Just for demonstration;
function check_imageornot(data){
...........
if -> image && exist -> return 'image_ok';
if -> image && not_exist -> return 'image_no';
if -> string -> return 'string';
}
}
NOTE: This function will be put into .js file so Javascript/jQuery way is needed (can be regex way in JS/jQuery too…)
You can’t tell if a file is an image just by looking at its name (or its URL). If you’re talking about a local file, you could use HTML5 file manipulation tools to open the file and sniff its contents. If the URL could be for a file anywhere on the Internet, however, you’ll have to send the URL to your server and have it figure out what it is.
edit — @GGG has an interesting idea in a comment.