get name of the remote image
Moderator: General Moderators
get name of the remote image
Hi,
Is it possible to get name of remote image before loading the image?
URL in form: 'domain.com/some.php?ID=1234'
Thanks,
Val.
Is it possible to get name of remote image before loading the image?
URL in form: 'domain.com/some.php?ID=1234'
Thanks,
Val.
Re: get name of the remote image
Could you expand a bit on what you are looking for? You are writing a PHP script, and want to find a way to get the URL of an image on another host which should be shown on the page you are generating from the PHP script? Sorry, I don't quite understand what you are looking for? 
Re: get name of the remote image
Thanks for quick replay, greip!
I have list of links to remote site:
'domain.com/some.php?ID=1234'
'domain.com/some.php?ID=1235'
...
But i dont want to download all images (they are big) - only images with spcific names,
so I have to check name of every image before loading.
Val.
I have list of links to remote site:
'domain.com/some.php?ID=1234'
'domain.com/some.php?ID=1235'
...
But i dont want to download all images (they are big) - only images with spcific names,
so I have to check name of every image before loading.
Val.
Re: get name of the remote image
What method are you using to grab images / pages from those URLs?
-Greg
-Greg
Re: get name of the remote image
I dont use any methods - if in browser(just found it) I put the URL: 'domain.com/some.php?ID=1235' it will show name of the image and ask me where to save the file.
Same with next number 1234, 1233...
Script has to check name of every file before loading few hundreds of them
Val.
Same with next number 1234, 1233...
Script has to check name of every file before loading few hundreds of them
Val.
Re: get name of the remote image
Since you are talking about URLs that are PHP scripts, there is no way to know what that PHP script is going to send to a browser (where you could find the image filename in the source code) unless you request the script to run and send you the results, such as by using cURL. But that would take essentially the same time as just loading them anyway, so I don't think there is any way to do that. If I'm wrong, surely someone will correct me.
Re: get name of the remote image
It sound like you are looking to automate a process you today run manually. When you type the URL manually into the browser, is the image name shown in the save-file dialogue something else than the URL you keyed in? If so, where does the image name come from?
Re: get name of the remote image
I see file name in save-fle dialog only. I think php script process ID number and send name and file.
Re: get name of the remote image
You could use cURL to fetch the page, follow the redirects and parse the resulting html for IMG links manually with regex or use php DOM tools.
If you provide a link to an example of a page and an image we could help you choose a method. But cURL + DOM is the most robust way to scrape sites.
If you provide a link to an example of a page and an image we could help you choose a method. But cURL + DOM is the most robust way to scrape sites.
Re: get name of the remote image
Yes, I know this technick, I just thought that if I go through all links directly, it would be easier.
If save dialog in browser show me name of jpg, should it be somewhere in a header?
Thanks,
Val.
If save dialog in browser show me name of jpg, should it be somewhere in a header?
Thanks,
Val.
Re: get name of the remote image
If the browser generates a save dialog, the server must have sent a Content-Disposition HTTP header. That header is where the browser finds the name of the file. For example,
Ordinarily, the server responds to either a GET or POST request sent by the browser. With those two types of requests, the server replies with a response containing both a head and a body. However, there is another type of request, HEAD, which tells the server to return only the head and not the body. You can use this to get the image file name without downloading the image data.
With cURL, a HEAD request is performed by enabling the CURLOPT_NOBODY option. Also enable CURLOPT_HEADER to get access to the head string.
Code: Select all
Content-Disposition: attachment; filename="image.png"With cURL, a HEAD request is performed by enabling the CURLOPT_NOBODY option. Also enable CURLOPT_HEADER to get access to the head string.
Re: get name of the remote image
Thanks for this hint!
Can you refere to some example of using CURLOPT_NOBODY option ?
Val.
Can you refere to some example of using CURLOPT_NOBODY option ?
Val.
Re: get name of the remote image
Second example in the manual
http://php.net/manual/en/book.curl.php
All options are here
http://www.php.net/manual/en/function.curl-setopt.php
FYI cURL does "go through the links directly" so to speak.
http://php.net/manual/en/book.curl.php
All options are here
http://www.php.net/manual/en/function.curl-setopt.php
FYI cURL does "go through the links directly" so to speak.
Re: get name of the remote image
Thanks a lot!