I have URL:
https://jumbo-beta.iskon.hr/dl/6c6e4510-765b-401f-9793-f98a8e6e941b
And i want to find out file details behind that URL. (Filname, size, etc.) I don't want to download the file, just find details.
Can this be done with php?
Thx
I have URL:
https://jumbo-beta.iskon.hr/dl/6c6e4510-765b-401f-9793-f98a8e6e941b
And i want to find out file details behind that URL. (Filname, size, etc.) I don't want to download the file, just find details.
Can this be done with php?
Thx
Yes, you have the power for do that!.
I think the best approach is getting it from HTTP headers, and another approach is downloading at temporary directory and extracting information from it.
Edit
Example
<?php
$headers = get_headers("https://jumbo-beta.iskon.hr/dl/6c6e4510-765b-401f-9793-f98a8e6e941b");
preg_match_all("/(?P<key>([\w-]+)):(\s+)?(?P<value>(.+))/", implode("\r\n", $headers), $matches);
$values = array_combine($matches['key'], $matches['value']);
preg_match('/filename="(?P<name>(.+))"/', $values['Content-Disposition'], $file);
$content_type = $values['Content-Type'];
$filesize = $values['Content-Length'];
$filename = $file['name'];
var_dump($content_type, $filesize, $filename);
And then you can access all ...
The output of following code ...
string 'image/jpeg; charset=ISO-8859-2' (length=31)
string '130677' (length=7)
string 'WWW.YIFY-TORRENTS.COM.jpg' (length=25)
get_headers
WILL download the entire file before returning, because it uses a GET
request.
Before calling get_headers
, use the following:
stream_context_set_default(array('http' => array('method' => 'HEAD')));
YES, in PHP there is a lot of functions that Return information about a file
finfo_file -- finfo::file — Return information about a file
Also there is too many functions on images processing: exif_read_data can help you!
<?php
$exif = exif_read_data("https://jumbo-beta.iskon.hr/dl/6c6e4510-765b-401f-9793-f98a8e6e941b", 0, true);
echo "test.jpg:<br />\n";
foreach ($exif as $key => $section) {
foreach ($section as $name => $val) {
echo "$key.$name: $val<br />\n";
}
}
?>
output :
test.jpg:
FILE.FileName: 6c6e4510-765b-401f-9793-f98a8e6e941b
FILE.FileDateTime: 0
FILE.FileSize: 130677
FILE.FileType: 2
FILE.MimeType: image/jpeg
FILE.SectionsFound:
COMPUTED.html: width="350" height="500"
COMPUTED.Height: 500
COMPUTED.Width: 350
COMPUTED.IsColor: 1