I wrote this code to integrate with filepicker.io, it takes the URL of the file and gets the header information:

$info = curl_init() or die('error 1');
        curl_setopt($info, CURLOPT_RETURNTRANSFER, 1);
        //curl_setopt($info, CURLOPT_PORT , 8089);
        curl_setopt($info, CURLOPT_URL, $url);
        curl_setopt($info, CURLOPT_CONNECTTIMEOUT, 30);
        curl_setopt($info, CURLOPT_NOBODY, true);
        //curl_setopt($info, CURLOPT_SSL_VERIFYPEER, 0);
        curl_exec($info);
        if(!curl_errno($info)){
            $response = curl_getinfo($info);
            echo "<pre>";
            echo var_dump($response);
            echo "</pre>";
        }else{
            echo "error!";
            echo "<br>" . curl_error($info);
        }

And here is a response:

array(26) {
  ["url"]=>
  string(55) "https://www.filepicker.io/api/file/CjDfxG0WSmGiY3O2eKDE"
  ["content_type"]=>
  string(9) "image/png"
  ["http_code"]=>
  int(200)
  ["header_size"]=>
  int(840)
  ["request_size"]=>
  int(86)
  ["filetime"]=>
  int(-1)
  ["ssl_verify_result"]=>
  int(0)
  ["redirect_count"]=>
  int(0)
  ["total_time"]=>
  float(2.805141)
  ["namelookup_time"]=>
  float(0.442366)
  ["connect_time"]=>
  float(0.46781)
  ["pretransfer_time"]=>
  float(0.873621)
  ["size_upload"]=>
  float(0)
  ["size_download"]=>
  float(0)
  ["speed_download"]=>
  float(0)
  ["speed_upload"]=>
  float(0)
  ["download_content_length"]=>
  float(965985)
  ["upload_content_length"]=>
  float(0)
  ["starttransfer_time"]=>
  float(2.805054)
  ["redirect_time"]=>
  float(0)
  ["certinfo"]=>
  array(0) {
  }
  ["primary_ip"]=>
  string(11) "79.125.4.68"
  ["primary_port"]=>
  int(443)
  ["local_ip"]=>
  string(11) "192.168.0.9"
  ["local_port"]=>
  int(51414)
  ["redirect_url"]=>
  string(0) ""
}

There is one massive thing missing - the file name, as I understand it that should be returned with the header or do I have to make a specific request for it. The filename is masked in the URL so I cannot use that.
Any suggestions would be great!

Member Avatar for diafol

The link gives me...

<img src="https://www.filepicker.io/api/file/CjDfxG0WSmGiY3O2eKDE" width="727" height="409">

I imagine that the rewritten url passes the info to a php (or similar) script to retrieve info either directly from the DB (blob) or even from a stored file and then transformed. Either way, I don't see how you could retrieve a filename for it, as the 'file' itself may not exist.

I've managed to get the header data but I need only the filename and I can't use http_parse_headers. Any ideas?

Here's the response

string(843) "HTTP/1.1 200 OK
Server: nginx
Date: Sun, 17 Nov 2013 15:39:10 GMT
Content-Type: image/png
Content-Length: 1766130
Content-Disposition: inline; filename="2013-09-14_12.16.37.png"
Cache-Control: public, max-age=3600, no-transform
Set-Cookie: session="VYl/XV7Sp/LFHqbQCo4qnV7qEDE=?_id=UydceDA1XHhjY1dceGRhIUxceDlhXHhlY1x4YzQlXHhlZGlXXHgxMDErJwpwMQou"; Domain=.filepicker.io; Path=/; HttpOnly
x-amz-id-2: DWJC6yuemJh7OcPAnAVwFGg5mWqWEd1cpZZddnFZ516ZNfGNSaNfRT7mg3fEplio
x-amz-request-id: CEFC6905BB2784B6
Last-Modified: Sun, 17 Nov 2013 15:39:04 GMT
ETag: "fbd465c27acdbae68d2fb905ce864472-1"
Accept-Ranges: bytes
X-File-Name: 2013-09-14_12.16.37.png
Access-Control-Allow-Headers: CONTENT-TYPE, X-NO-STREAM
Access-Control-Allow-Methods: DELETE, GET, HEAD, POST, PUT
Access-Control-Allow-Origin: *
Access-Control-Max-Age: 21600

EDIT: Just to clarify, this is for a client who wants it to run of shared hosting, and this particular shared hosting doesn't support the http php library.

Member Avatar for diafol

Use regex if the above is in a string.

Find 'filename="' extract the content before the next '"'

$pattern = '/filename=\"(.*)\"/';
//subject will be the header in string

preg_match($pattern, $subject, $matches);

echo $matches[1];
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.