Login   Register  
PHP Classes
elePHPant
Icontem

File: examples/example17_upload_form.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Naveed ur Rehman  >  PHP Megaupload.com Class  >  examples/example17_upload_form.php  >  Download  
File: examples/example17_upload_form.php
Role: Example script
Content type: text/plain
Description: Upload a file to megaupload.com through HTML form
Class: PHP Megaupload.com Class
Manage files and folders megaupload.com accounts
Author: By
Last change:
Date: 3 years ago
Size: 2,293 bytes
 

Contents

Class file image Download
<?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>