Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ifrit's avatar
Level 2

Downloading a file from an external source

Is there a way to download a file from a url, but the url doesn't have an extension? So what I mean is, for example I have a file on google drive and I click on the get link option and that link doesn't have an extension it only has this

https://drive.google.com/file/a/random_text/view?usp=sharing

How would I go about saving that to my storage folder? At the moment I only have this in my code

public function getFile($url){
    dd(pathinfo($url));
}

and that only gives me

array:3 [
  "dirname" => "https://drive.google.com/file/a/random_text/"
  "basename" => "view?usp=sharing"
  "filename" => "view?usp=sharing"
]
0 likes
4 replies
Ifrit's avatar
Level 2

@sinnbeck - I'm not sure I'm doing this correctly this is how I did my code

return response()->streamDownload(function($url){
           file_put_contents('test.html', $url);
        });

and all I get back is

Saved filename is HTTP/1.0 200 OK
Cache-Control: no-cache, private
Date:          Wed, 02 Feb 2022 12:47:22 GMT

I don't want to use the package you suggested because the link might not come from google

Please or to participate in this conversation.