0

i save this as php file in local and this works fine in browser

<form name="Form" method="post" action="http://www.idx.co.id/en-us/home/listedcompanies/issuedhistory.aspx" id="Form" enctype="multipart/form-data"><div><input type="hidden" name="StylesheetManager_TSSM" id="StylesheetManager_TSSM" value="" /><input type="hidden" name="ScriptManager_TSM" id="ScriptManager_TSM" value="" /><input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="dnn$ctr951$MainView$lbDownload" /><input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" /></div></form>
<script>
document.getElementById("Form").submit();
</script>

but how to do this in curl? i tried

function download($url, $path)
    {
      $fp = fopen ($path, 'w');
      $ch = curl_init();
      curl_setopt( $ch, CURLOPT_URL, $url );
      curl_setopt( $ch, CURLOPT_RETURNTRANSFER, false );
      curl_setopt( $ch, CURLOPT_BINARYTRANSFER, true );
      curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
      curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 30 );
      curl_setopt( $ch, CURLOPT_FILE, $fp );
      $params = "StylesheetManager_TSSM=&ScriptManager_TSM=&__EVENTTARGET=dnn$ctr951$MainView$lbDownload&__EVENTARGUMENT=";
      curl_setopt($ch, CURLOPT_POSTFIELDS,$params);
      curl_exec( $ch );
      curl_close( $ch );
      fclose( $fp );

      if (filesize($path) > 0) return true;
    }

    $url = 'http://www.idx.co.id/en-us/home/listedcompanies/issuedhistory.aspx';
    $path = 'corpactions.csv';

    if (download($url, $path)){
        echo 'Download complete!'; 
    }

but it doesn't work as expected, it downloaded another page

user3725273
  • 15
  • 1
  • 4

1 Answers1

1

Try Changing this

$params = "StylesheetManager_TSSM=&ScriptManager_TSM=&__EVENTTARGET=dnn$ctr951$MainView$lbDownload&__EVENTARGUMENT=";

Into this:

$params = 'StylesheetManager_TSSM=&ScriptManager_TSM=&__EVENTTARGET=dnn$ctr951$MainView$lbDownload&__EVENTARGUMENT=';

The Problem could be that $czt951 will be parsed as php var.

For more Details read this Answer: https://stackoverflow.com/a/3446286/2441442

Community
  • 1
  • 1
Christian Gollhardt
  • 16,510
  • 17
  • 74
  • 111