-1

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

zonelsk
  • 235
  • 1
  • 5
  • 14

3 Answers3

0

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)
Andrey
  • 1,476
  • 1
  • 11
  • 17
  • how about proving some code at least –  Jan 05 '14 at 22:39
  • Hi, i tryed with HTTP headers, but it didn't work for me. (Don't know hat I did wrong). This works. Thanx. Sorry for not posting any code, but I tought that question was so trivial (and it was). – zonelsk Jan 05 '14 at 22:53
0

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')));
Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
  • When I add this before calling get_header i don't get full info. Printing $content_type, $filesize , and $filename i get: text/plain; charset=UTF-8 130677 – zonelsk Jan 05 '14 at 23:27
0

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

Community
  • 1
  • 1
shayan
  • 1
  • 1