0

There is a site https://salmonprice.nasdaqomxtrader.com/public/report;jsessionid=110C4ADED76BEEE6E08401DFF1539728?0 from where we need to download an excel file on a periodical basis. The file link is below:

https://salmonprice.nasdaqomxtrader.com/public/report?0-3.ILinkListener-loginMenu-downloadIndexHistoryLink

When we click the above link the excel file started to download.

I am trying in the following way to save the file in PHP:

$url = https://salmonprice.nasdaqomxtrader.com/public/report;jsessionid=AC40D42FFE3C6F71B7C0D74F7545AC87?0-3.ILinkListener-loginMenu-downloadIndexHistoryLink'; $file_name = "test.xls"; if(file_put_contents( $file_name,file_get_contents($url))) { echo "File downloaded successfully"; } else { echo "File downloading failed."; } 

but this attempt downloading web page content not excel file content. How can I solve this problem?

6
  • file_get_contents is the most basic way to download something from a remote source and you sometimes don't get the best error messages from it. In fact, when it fails it returns false but only emits a warning. Regardless, turn on full error reporting in PHP to see if you can see the warning. There are a myriad of reasons why it won't work, the most likely case is that the remote site is detecting that you are a robot. You should contact that site to ask for permission. You can also look into alternative methods to download files with more power. Commented Nov 4, 2020 at 14:55
  • This is the best way to achieve this : Use cURL Commented Nov 4, 2020 at 15:00
  • Have you tried the link in a different browser (or incognito). Maybe they use a cookie to serve you the right file. That does not exist for new users. Commented Nov 4, 2020 at 15:02
  • Are you sure jsessionid does not change? Commented Nov 4, 2020 at 15:10
  • Yes, It is changing Commented Nov 4, 2020 at 15:19

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.