2017 © Pedro PelĂĄez
 

library mega

Mega.co.nz library

image

glutamatt/mega

Mega.co.nz library

  • Friday, October 18, 2013
  • by glutamatt
  • Repository
  • 2 Watchers
  • 2 Stars
  • 21 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 37 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

MEGA PHP Client Library

PHP client library for the MEGA API., (*1)

This version come from https://github.com/smartinm/mega-php-client. Thanks to contributors !, (*2)

I've added some features to use the max bandwidth thanks to forks, (*3)

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

2013/10/17 : Links from http://megacrypter.com/ handled, (*4)

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

Requirements

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

Installation with composer

```composer.json { "require": { "glutamatt/mega": "dev-master" }, "minimum-stability": "dev" }, (*6)



Creating the client ------------------- ### Using the constructor ```php $mega = new MEGA();

Using a static factory method

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

This is equivalent to:, (*7)

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

Changing the default MEGA API server

MEGA::set_default_server(MEGA::SERVER_EUROPE);

Working with public files

Download public files not require authentication., (*8)

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'];
$file_info = $mega->public_file_info_from_link($link);

This is equivalents to:, (*9)

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

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., (*10)

Downloading files

Using streams

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

Returning content

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

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

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

  • The node_file_save() function is equivalent to public_file_save()
  • The node_file_download() function is equivalent to public_file_download()

User 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

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

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

// ...

Credits

  • This library has been written by Sergio MartĂ­n (@smartinm) as a port of official MEGA Javascript code., (*11)

  • Part of the code is based on the work done by Julien Marchand., (*12)

The Versions

18/10 2013

dev-master

9999999-dev https://github.com/glutamatt/mega-php-client

Mega.co.nz library

  Sources   Download

MIT

The Requires

 

by Mathieu Morlon

download mega