• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 107
  • Last Modified:

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 ?
0
marcel sith
Asked:
marcel sith
  • 2
  • 2
  • 2
  • +3
1 Solution
 
Marco GasiFreelancerCommented:
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

0
 
huacatCommented:
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.
0
 
Marco GasiFreelancerCommented:
basename extract the filename from the given string: it's up to you to pass the correct string.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
marcel sithAuthor Commented:
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
0
 
Ray PaseurCommented:
... 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
0
 
marcel sithAuthor Commented:
ok guys thank you so much for the help
0
 
huacatCommented:
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.
0
 
Danny ChildIT ManagerCommented:
If, as the question suggests, you have a list of these URLs in Excel, you can use this formula to extract just the filename from the end of the string.  It assumes the URL is in A1

=IF(ISERROR(FIND("/",A1)),A1,RIGHT(A1,LEN(A1)-FIND("~",SUBSTITUTE(A1,"/","~",LEN(A1)-LEN(SUBSTITUTE(A1,"/",""))))))

It should work with strings of many different lengths, and with different numbers of subfolders, etc.
0
 
frankhelkCommented:
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
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now