PHPackages                             glutamatt/mega - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. glutamatt/mega

ActiveLibrary[HTTP &amp; Networking](/categories/http)

glutamatt/mega
==============

Mega.co.nz library

3342PHP

Since Oct 17Pushed 12y ago1 watchersCompare

[ Source](https://github.com/glutamatt/mega-php-client)[ Packagist](https://packagist.org/packages/glutamatt/mega)[ RSS](/packages/glutamatt-mega/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependenciesVersions (1)Used By (0)

MEGA PHP Client Library
=======================

[](#mega-php-client-library)

PHP client library for the [MEGA API](https://mega.co.nz/#developers).

This version come from . Thanks to contributors !

I've added some features to use the max bandwidth thanks to forks

```
require_once 'vendor/autoload.php';

use Glutamatt\Mega\MEGA;

$mega = new MEGA() ;
$link = 'https://mega.co.nz/#!IdOfThEFilE!ThELonG_KeyOfDaFiLE' ;
$mega->public_file_save_from_link($link, 'where_file_will_be_saved/' );
```

Features
--------

[](#features)

2013/10/17 : Links from  handled

*Note: This library is still under development and incomplete, so the API is subject to change.*

Requirements
------------

[](#requirements)

- PHP 5.x
- PHP Mcrypt extension
- PHP OpenSSL extension
- PHP cURL extension
- PHP pcntl extension

Installation with composer
--------------------------

[](#installation-with-composer)

```
{
    "require": {
        "glutamatt/mega": "dev-master"
    },
    "minimum-stability": "dev"
}
```

Creating the client
-------------------

[](#creating-the-client)

### Using the constructor

[](#using-the-constructor)

```
$mega = new MEGA();
```

### Using a static factory method

[](#using-a-static-factory-method)

```
$mega = MEGA::create_from_login($email, $password);
```

This is equivalent to:

```
$mega = new MEGA();
$mega->user_login_session($email, $password);
```

### Changing the default MEGA API server

[](#changing-the-default-mega-api-server)

```
MEGA::set_default_server(MEGA::SERVER_EUROPE);
```

Working with public files
-------------------------

[](#working-with-public-files)

Download public files not require authentication.

### Gettings file info

[](#gettings-file-info)

```
$mega = new MEGA();

$file_info = $mega->public_file_info($ph, $key);
var_dump($file_info);

// Print filename and size
echo 'Filename: ' . $file_info['at']['n'];
echo 'Size: ' . $file_info['s'];
```

### Using links

[](#using-links)

```
$file_info = $mega->public_file_info_from_link($link);
```

This is equivalents to:

```
$info = MEGA::parse_link($link);
$file_info = $mega->public_file_info($info['ph'], $info['key']);
```

### Downloading public files

[](#downloading-public-files)

```
// Save file to current directory.
$filepath = $mega->public_file_save($ph, $key);
echo 'File saved in ' . $filepath;

// Equivalent using exported link
$filepath = $mega->public_file_save_from_link($link);
echo 'File saved in ' . $filepath;
```

See below for more examples.

Downloading files
-----------------

[](#downloading-files)

### Using streams

[](#using-streams)

```
// Write to file
$fp = fopen($file, 'wb');
$content = $mega->public_file_download($ph, $key, $fp);
fclose($fp);
```

### Returning content

[](#returning-content)

```
// Get content using temporary stream
$content = $mega->public_file_download($ph, $key);
```

### Saving to disk

[](#saving-to-disk)

```
// Save file to temporary directory.
$tmp = sys_get_temp_dir();
$file = $mega->public_file_save($ph, $key, $tmp);
echo 'File saved in ' . $file;
```

Private files
-------------

[](#private-files)

### Listing

[](#listing)

```
$mega = MEGA::create_from_user($email, $password);

$files = $mega->node_list();
print_r($files);

// Get file info
$file_info = $mega->node_file_info($files['f'][5]);
print_r($file_info);
```

### Downloading

[](#downloading)

- The `node_file_save()` function is equivalent to `public_file_save()`
- The `node_file_download()` function is equivalent to `public_file_download()`

User session
------------

[](#user-session)

### Store session

[](#store-session)

```
$mega = MEGA::create_from_user($email, $password);

// ...

// Get current session (as a base64 string)
$session = $mega->session_save();

// Store in a safe place!
store_session($session);
```

### Restoring session

[](#restoring-session)

```
// Retrive saved session
$session = get_session();

// Create client from previous session
$mega = MEGA::create_from_session($session);

// ...
```

Credits
-------

[](#credits)

- This library has been written by Sergio Martín ([@smartinm](http://twitter.com/smartinm)) as a port of official MEGA Javascript code.
- Part of the code is based on the work done by [Julien Marchand](http://julien-marchand.fr/).

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 69.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1442992?v=4)[Mathieu Morlon](/maintainers/glutamatt)[@glutamatt](https://github.com/glutamatt)

---

Top Contributors

[![glutamatt](https://avatars.githubusercontent.com/u/1442992?v=4)](https://github.com/glutamatt "glutamatt (9 commits)")[![smartinm](https://avatars.githubusercontent.com/u/260683?v=4)](https://github.com/smartinm "smartinm (3 commits)")[![Yoeori](https://avatars.githubusercontent.com/u/285744?v=4)](https://github.com/Yoeori "Yoeori (1 commits)")

### Embed Badge

![Health badge](/badges/glutamatt-mega/health.svg)

```
[![Health](https://phpackages.com/badges/glutamatt-mega/health.svg)](https://phpackages.com/packages/glutamatt-mega)
```

###  Alternatives

[php-http/cache-plugin

PSR-6 Cache plugin for HTTPlug

25025.5M80](/packages/php-http-cache-plugin)[illuminate/http

The Illuminate Http package.

11937.2M6.6k](/packages/illuminate-http)[rdkafka/rdkafka

A PHP extension for Kafka

2.2k20.0k1](/packages/rdkafka-rdkafka)[httpsoft/http-message

Strict and fast implementation of PSR-7 and PSR-17

87930.4k113](/packages/httpsoft-http-message)[mezzio/mezzio-router

Router subcomponent for Mezzio

265.3M84](/packages/mezzio-mezzio-router)[serpapi/google-search-results-php

Get Google, Bing, Baidu, Ebay, Yahoo, Yandex, Home depot, Naver, Apple, Duckduckgo, Youtube search results via SerpApi.com

69122.6k](/packages/serpapi-google-search-results-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
