Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

20 Commits

Repository files navigation

Fork Differences

This fork fixes the function node_publish. You can use this function to generate private download links for files stored on your MEGA account. node_public_handle was also created to assist with this process, though it was not fully documented when it was written a year ago.

Here is how I implemented the function node_publish:

//Filename you want publish a link for.$filename = "Test.zip";
//Returns the full list of files.$files = $mega->node_list();
//This loop is not efficient done for testing.//Find the file in the array and return its position.$x = 0;
while ($x < count($files['f'])) {
if (!empty($files['f'][$x]['a']['n'])) {
if ($files['f'][$x]['a']['n'] == $filename) {
echo"Found: ".$x;
$foundnumber = $x;
}
}
$x++;
}
//Get the publish link, and display.echo"<pre>";
echo"URL: ";
if (!empty($foundnumber)) {
$url = $mega->node_publish($files, $foundnumber);
echo$url;
}
echo"</pre>";

MEGA PHP Client Library

PHP client library for the MEGA API.

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

Requirements

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

Creating the client

Using the constructor

$mega = newMEGA();

Using a static factory method

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

This is equivalent to:

$mega = newMEGA();
$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.

Gettings file info

$mega = newMEGA();
$file_info = $mega->public_file_info($ph, $key);
var_dump($file_info);
// Print filename and sizeecho'Filename: ' . $file_info['at']['n'];
echo'Size: ' . $file_info['s'];

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

// 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

Using streams

// Write to file$fp = fopen($file, 'wb');
$size = $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

Saving session

$mega = MEGA::create_from_user($email, $password);
// ...// Get current session as a base64 string$session = MEGA::session_save($mega);
// Store in a safe place!db_store_session($session);

Restoring session

// Retrive saved session$session = db_get_session();
// Create client from previous session$mega = MEGA::create_from_session($session);
// ...

Status

Operations that don't require user authentication

MethodDescriptionStatus
public_file_infoRequest public file infoImplemented
public_file_info_from_linkRequest public file infoImplemented
public_file_downloadDownload a public fileImplemented
public_file_download_from_linkDownload a public fileImplemented
public_file_saveDownload and save a public file to diskImplemented
public_file_save_from_linkDownload and save a public file to diskImplemented

Operations that require user authentication

MethodDescriptionStatus
node_listRetrieve folder or user nodesImplemented
node_file_infoRequest file node infoImplemented
node_file_downloadDownload a file nodeImplemented
node_file_saveDownload and save a file node to diskImplemented
node_addAdd/copy nodesNot implemented
node_deleteDelete nodeNot implemented
node_moveMove nodeNot implemented
node_updateSet node attributesNot implemented
node_publish / node_unpublishCreate/delete public handleNot implemented
node_shareCreate/modify/delete outgoing shareNot implemented

Credits

  • This library has been written by Sergio Martín (@smartinm) as a port of official MEGA Javascript code.

  • Part of the code is based on the work done by Julien Marchand.

  • This projected is licensed under the terms of the MIT license.

Bitdeli Badge

About

MEGA PHP Client Library

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages