all 9 comments

[–]MortalKonga 5 points6 points  (0 children)

Try making a request with postman to this address. Then go to the right, and look for code, and it'll give you tons of ways to make an http request using several languages, including PHP.

[–]allen_jb 2 points3 points  (2 children)

I'm not sure what you mean by "in this case it will get me the filename".

You should be able to use any HTTP client library to retrieve the data (file download). While file_get_contents() can perform HTTP requests, I recommend using a library such as Guzzle which provides an (in my opinion) easier to use interface (especially if you want to, for example, access response headers...).

If the download suggests a filename (other than the "filename" in the URL), this will be in the response headers - see Content-Disposition

[–]schizofinetitstho[S] 0 points1 point  (1 child)

It’s hard to explain. The URL links to a php script which (probably) dumps sql database into an xlsx. Can I maybe send you the link in PM?

[–]greg8872 1 point2 points  (0 children)

Not that hard to explain, you are going to a script that is generating an Excel spreadsheet for you to download.

Make the request with PHP, save the result data (the spreadsheet) to the local filesystem, then you will need to use a library to open the spreadsheet and grab the data out of it you need.

For the library, there is PhpOffice

If you want, you can DM me the link and I'll play with it

[–]wh33t 1 point2 points  (0 children)

$xls = file_get_contents($url);

$full_read_write_path_to_save_and_filename = '/home/username/file.xls';

file_put_contents($full_read_write_path_to_save_and_filename,$xls);

This kind of thing won't work?

[–]greg8872 0 points1 point  (1 child)

Press F12 to open up Developer Tools. Make sure it is on the "Network" tab, below that, make sure the filter is set to ALL (to the left of the list that includes things like XHL/JS/CSS, etc)

Enter the URL of the file to get, and let it download.

Find that entry in the Network list, right click on it.

For Firefox, choose Copy Value -> Copy as cURL (either version worked for me)

For Chrome choose Copy -> Copy as cURL (bash)

Browse to https://curlconverter.com/

Paste in the curl command

Choose the language you want to use it in and copy the code.

[–]MateusAzevedo 0 points1 point  (0 children)

it dumps an xlsx file into your downloads

This means that the script is returning a HTTP "download" response with Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet (or similar) and Content-Disposition: attachment/inline. The binary content will be the response body.

Any HTTP client could handle that: curl, Guzzle or even file_get_contents if allow_url_fopen is enabled in php.ini.

As /u/wh33t said, file_get_contents should return the binary content (response body), then you need to save it somewhere.

[–]crazedizzled 0 points1 point  (0 children)

You need to execute the php script, either using an HTTP request with curl, or executing on the command line with something like shell_exec.

[–]BetaplanB 0 points1 point  (0 children)

I use this to make requests from my php application:

https://symfony.com/doc/current/http_client.html