title: How to generate mega.nz direct download link using php
body: <p>Hi I want to get direct download link from mega.nz using php. but this script downloading wrong file. how to fix it? this is php my script.</p>
  
  <pre><code>    error_reporting(0);
  $url = "https://mega.nz/#!YfxRWbZC!8ckee4WWEdIsdoA-8gJaEoQjGp8mD0z6iJJMSOhgGh0";
  preg_match("/!(.+?)!/", $url, $output_array);
  $fileID = $output_array[1];
  $domain = "mega.nz";
  $lang = "en";
  $apiURL = "https://eu.api.mega.co.nz/cs?domain=$domain&amp;lang=$lang";
  
  $value = array(
    array(
      'a' =&gt; 'g',
      'g' =&gt; 1,
      'ssl' =&gt; 1, //0, 1, 2 (default is 2)
      'p' =&gt; $fileID) // File id here
    );
  
    $rawPOST = json_encode($value);
  
    $ch = curl_init();
  
    curl_setopt($ch, CURLOPT_URL,            $apiURL );
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
    curl_setopt($ch, CURLOPT_POST,           true );
    curl_setopt($ch, CURLOPT_POSTFIELDS,     $rawPOST );
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36');
    curl_setopt($ch, CURLOPT_HTTPHEADER,     array('Content-Type: text/plain;charset=UTF-8'));
  
    $result=curl_exec($ch);
  
    $jsonResult = json_decode($result);
  
    echo "&lt;pre&gt;";
    print_r($jsonResult);
    echo "&lt;/pre&gt;";
  
    //$directLink = $jsonResult[0]-&gt;g;
  </code></pre>
  
  <p>result give like this : </p>
  
  <pre><code>Array
  (
      [0] =&gt; stdClass Object
          (
              [s] =&gt; 670324
              [at] =&gt; itsRcC_Uk8GQSJRgJCj1qT0qyUOWuWbtEb1TCsTQkZkduPhcMVcBlBHHAdjo55Ox-e4YIEAtN4gfCPWjSdoqAQ
              [msd] =&gt; 1
              [g] =&gt; https://gfs208n103.userstorage.mega.co.nz/dl/GbRfvzoyX4eL0gL4FQtejHQGDVo_Zre5VtDnD-JN8KYkmv6rz3SI9THmPNwjnrDyCdUQZ-omVcVcmbEnJiPFqu0Gc_b_GMh-MJBLtC2Qs4FQix9huWVR2-3pLo-7oQ
          )
  
  )
  </code></pre>
  
  <p><strong>BUT THIS LINK($directLink = $jsonResult[0]->g;) DOWNLOADING WRONG FILE..How to fix it?</strong></p>