<?php
/******************************************************************************
HOW TO USE "PHP MEGAUPLOAD.COM CLASS"
******************************************************************************
Example #17: Upload a file to megaupload.com through HTML form [caution: not for windows environment]
******************************************************************************
Author: Naveed-ur-Rehman
Email: naveed@naveedurrehman.com,
naveed.coder@gmail.com,
naveed.ur.rehman@hotmail.com
Website: http://www.naveedurrehman.com/
******************************************************************************
*/
require_once('../class/megaupload.class.php'); //php megaupload.com class file
require_once('credentials.php'); //Your signing in credentails of megaupload.com account
$megaupload = new megaupload_class(); //Initializing the class
$megaupload->username=$username; //Setting credentails (loaded from credentails.php)
$megaupload->password=$password;
if(is_uploaded_file($_FILES['file']['tmp_name']))
{
$isconnect = $megaupload->connect(); //Return: 0=trouble, 1=validated and connected
if($isconnect==1)
{
//Uploading to local server (make sure that the current directory has writing permissions)
$filename = $_FILES['file']['name'];
move_uploaded_file($_FILES['file']['tmp_name'],$filename);
$details = $_REQUEST["details"];
//Uploading to megaupload.com
$newfileid = $megaupload->upload($filename,$details);
if($newfileid)
{echo "File has been uploaded. New file's link is <a href='http://www.megaupload.com/?d=$newfileid'>http://www.megaupload.com/?d=$newfileid</a>";}
else
{echo "Error while uploading file.";}
//Removing file's copy on local server
@unink($filename);
}
else
{
echo "Error occured while connecting to megaupload.com. May be username and/or password supplied is invalid.";
}
$megaupload->disconnect(); //Disconnect to release everything
}
?>
<h1>Upload to megaupload.com</h1>
<form method="post" enctype="multipart/form-data">
File: <input type="file" name="file" />
Details: <input type="text" name="details" />
<input type="submit" value="Upload">
</form>
|