0

I want to download a PDF file from our File Storage. But I get following error message while using file_get_contents()

Warning: file_get_contents(https://savatriplef01.file.core.windows.net/uploadmytriplef/MyTripleF/Inkomend/Commissie Afrekening/Test Bestand_L=TestLeverancier.pdf?st=2020-09-22T08%3A45%3A26Z&se=2088-07-16T08%3A45%3A00Z&sp=rl&sv=2018-03-28&sr=s&sig=ANWMpYimZlvEM4qDVuDpljy%2B4KNHT%2BC47qtvrsDlXno%3D): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in /home/vdouser/domains/mytriplef.nl/public_html/test.php on line 114

The file is name is downloaded and saved in FTP folder but the file size is 0kb and damaged.

Here is the code I am using:

file_put_contents("./azure_storage/".$folderName."/".$fileName."", file_get_contents($fileUrlWithSAS));

When I echo fileUrlWithSAS it outputs following URL: https://savatriplef01.file.core.windows.net/uploadmytriplef/MyTripleF/Inkomend/Commissie Afrekening/Test Bestand_L=TestLeverancier.pdf?st=2020-09-22T08%3A45%3A26Z&se=2088-07-16T08%3A45%3A00Z&sp=rl&sv=2018-03-28&sr=s&sig=ANWMpYimZlvEM4qDVuDpljy%2B4KNHT%2BC47qtvrsDlXno%3D

When you visit it it downloads the PDF but the stored file is damaged.

Does anyone know why the file is not downloaded good on our server?

Thanks.

Tring Bing
  • 17
  • 1
  • 1
    If your URL has spaces, they are not allowed - https://stackoverflow.com/questions/497908/is-a-url-allowed-to-contain-a-space – Nigel Ren Oct 01 '20 at 10:15
  • _“When you visit it it downloads the PDF”_ - no it doesn’t, it shows me a small response in XML format, that contains the error message _“This request is not authorized to perform this operation.”_ – 04FS Oct 01 '20 at 10:21
  • @04FS it can only be accessed when IP is whitelisted – Tring Bing Oct 01 '20 at 10:23
  • 1
    And the IP of your server, that you are making this request from, _is_ white-listed? But as Nigel mentioned, you should start by applying proper URL encoding here. Browsers do this automatically, when you submit something via the address bar, but `file_gets_content` doesn’t. – 04FS Oct 01 '20 at 10:26

0 Answers0