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:
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?
file_get_contentsis 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.jsessioniddoes not change?