Link to home
Start Free TrialLog in
Avatar of marcel sith
marcel sith

asked on

How can i extract image original name from URL?

I'm a beginner,my question is how how can i extract image name from URL. lets say an Image in this form "https://media.8ch.net/file_store/dba2bf277a91c75d94e48d47e03024784decb09b385fc3a4b8 81e32e4bc1c727.jpg"
how can i get it's original name ?
Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

Use http://php.net/manual/en/function.basename.php function:

$filename = basename("https://media.8ch.net/file_store/dba2bf277a91c75d94e48d47e03024784decb09b385fc3a4b8 81e32e4bc1c727.jpg");

Open in new window

Avatar of huacat
huacat

Basename just extract the stored file name of that file.
The orginal file name is different, I think Marcel want to know the file name like before stored at server.

for example, the 8ch.net page show codes like below:

<a download="14449883_253103011752100_8604454551979855724_n.jpg" href="https://8ch.net/file_store/d141f83bf107454f5bd83b40b334fdaf3d001e696403f919bf1075f9b53309c9.jpg" title="Save as original filename (14449883_253103011752100_8604454551979855724_n.jpg)">14449883_253103011752100_8….jpg</a>

Open in new window


The file URL is https://8ch.net/file_store/d141f83bf107454f5bd83b40b334fdaf3d001e696403f919bf1075f9b53309c9.jpg but the orginal file name is 14449883_253103011752100_8604454551979855724_n.jpg

If you want to get the original file name, you need to grab the html page and parse the links.
basename extract the filename from the given string: it's up to you to pass the correct string.
Avatar of marcel sith

ASKER

huacat
That's exactly what i want, but excuse me, this would sound pretty amateur, but how can i parse the links ?
can you offer me any guide to the whole process ? I'm not by any means an expert in that field so i guess i need more help, and thanks for the replies
... how can i parse the links ?
You may be able to get better help from E-E or any other online forum if you can use the SSCCE.  In this case we would need to see the URL of the web page you want to parse.  We would need to know which links you want to extract.  Once we understand that information we can probably show you how to do it.

If you're new to PHP and want to learn the language, this article can help you get started.
https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html
ok guys thank you so much for the help
Hi Marcel,

You need to learn the regexp and some shell scripts or a language to parse html, anyway, I give a sample below:

It parse the https://8ch.net/pol/res/7805200.html page, and list all orignal file name(post filename):
You should run below command at a Unix server or with Cygwin at Windows system.
curl -s https://8ch.net/pol/res/7805200.html | sed 's/<\/p>/<\/p>\r\n/g' | sed -n 's:.*"postfilename">\(.*\)</span>.*:\1:p' | sed 's:</span>)::g'

Open in new window


The output:
Cerj6BFWwAAf-rq.jpg large.jpg
1443849993124.jpg
1468117291744.png
SmugPlushieKek.jpg
1392571678789.jpg
1354659143392.jpg
1470529530964.gif
hillaryREKT_pepe.gif
Alpha-5.jpg
414.jpg
muslimquestioner.jpeg
1471066461424.png
votebar.png
1476067639990.jpg
kek-fly.jpg
Obama_fly21.jpg
moshi moshi.JPG
hanslaugh.webm
1476068047714s.jpg
1470901536488.jpg
pepe maga 2.jpg
Trump Stand.jpg
sweet.webm
Happy_merchant_preview.webm
__23.png
wtf_i_love_hillary_now.jpg
Yuri 114.png
Trump on Trump.webm
1476066902928.jpg
TheClintons.jpeg
kek______.jpg
KekSighting.png
nuclear-explosion-emp.jpg
stop_penis_erect_archer.gif
final solution.jpg
made of rape.jpg
1473693098196.jpg
....

If you want to process all pages, you need make a crawler/spider to grab all pages.
ASKER CERTIFIED SOLUTION
Avatar of Danny Child
Danny Child
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Accept: DanCh99 (https:#a41836816)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

frankhelk
Experts-Exchange Cleanup Volunteer