Skip to content

Instantly share code, notes, and snippets.

@MBRCTV
Last active July 18, 2024 17:38
Show Gist options
  • Save MBRCTV/b46993d1e584ce9640e73643856b0644 to your computer and use it in GitHub Desktop.
Save MBRCTV/b46993d1e584ce9640e73643856b0644 to your computer and use it in GitHub Desktop.
Mega.nz Direct Link Generator
<?php
echo '<html><head><title>Mega downloader</title></head><body><h2>Enter Url</h2><form action="mega.php" method="POST"> <br> URL: <input type="text" name="URL"> <br><input type="submit" value="Submit"></form>';
if ($_POST) {
error_reporting(0);
$url = $_POST['URL'];
preg_match("/!(.+?)!/", $url, $output_array);
$fileID = $output_array[1];
$domain = "meganz";
$lang = "en";
$apiURL = "https://eu.api.mega.co.nz/cs?domain=$domain&lang=$lang";
$value = array(
array(
'a' => 'g',
'g' => 1,
'ssl' => 0, //0, 1, 2 (default is 2)
'p' => $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);
$directLink = $jsonResult[0]->g;
$fileSize = $jsonResult[0]->s;
echo "URL: $directLink";
echo '<br>';
echo "File Size: $fileSize bytes";
echo '<br>';
}
echo '</body>
</html>';
?>
@neutrino658
Copy link

the link perfect get ....
but the file not working ,why
is it encrypted or what...

@kaizoku75
Copy link

same here neutrino658
how can we fix that?

@RohanDebroy
Copy link

RohanDebroy commented Oct 14, 2020

It is working fine all you have to do is decrypt it.
use mega.py python library it will help.

same here neutrino658
how can we fix that?

@asman03
Copy link

asman03 commented Dec 23, 2020

sory, im newby with this. so how i can use this code to download my mega link?

@fixcoderu
Copy link

sory, im newby with this. so how i can use this code to download my mega link?

replace regexp:
preg_match("/!(.+?)!/", $url, $output_array);
width
preg_match("/file/(.+?)#/", $url, $output_array);

@Moustafa-desha
Copy link

can explain please how can use it to download link from mega ?

@alxb421
Copy link

alxb421 commented Apr 23, 2021

can explain please how can use it to download link from mega ?

you need to upload the php into your webserver, It is used as a proof of concept, you will need to design the webpage for it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment