Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How can i extract image original name from URL?

Posted on 2016-10-08
9
Medium Priority
?
87 Views
Last Modified: 2016-11-11
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
Comment
Question by:marcel sith
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +3
9 Comments
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 41835560
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
 
LVL 7

Expert Comment

by:huacat
ID: 41835586
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
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 41835594
basename extract the filename from the given string: it's up to you to pass the correct string.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:marcel sith
ID: 41835596
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
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 41835767
... 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
 

Author Comment

by:marcel sith
ID: 41835789
ok guys thank you so much for the help
0
 
LVL 7

Expert Comment

by:huacat
ID: 41836357
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
 
LVL 23

Accepted Solution

by:
Danny Child earned 2000 total points
ID: 41836816
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
 
LVL 14

Expert Comment

by:frankhelk
ID: 41883549
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

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question