Get file from remote server using httpful php library

1k Views Asked by At

`I have a file stored on a strato hidrive which I'm able to access directly using webdav and authentication like so:

https://username:[email protected]/path/to/my/file.zip

When I paste that in my address bar I can directly download the file. But I'm writing a small file getter script which accepts the filename as a parameter in the URL and it will generate the download:

http://example.com/getfile.php?filename=file.zip

That should pop up a download dialog the same way the direct link would

I want to use the httpful php library to download the file if possible (not cURL)

1

There are 1 best solutions below

0
Ortixx On BEST ANSWER

Ended up being quite simple:

$response = Request::getQuick($url);

$path = parse_url($url, PHP_URL_PATH);
$filename = substr($path, strrpos($path, '/') + 1);
header('Content-Type: ' . $response->content_type);
header('Content-Disposition: attachment; filename="' . $filename . '";');
header('Content-Length: ' . $response->headers['content-length']);
readfile($url);