PHP Classes
elePHPant
Icontem

File: example/file_upload.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of windylea  >  MediaFire API PHP Library  >  example/file_upload.php  >  Download  
File: example/file_upload.php
Role: Example script
Content type: text/plain
Description: Example of file uploading
Class: MediaFire API PHP Library
Upload and retrieve files to MediaFire service
Author: By
Last change: Update file
Date: 2 years ago
Size: 2,718 bytes
 

Contents

Class file image Download
<?php
/*
 * Required parameters
 */
$appId = "";
$apiKey = "";
$email = "";
$password = "";

if (
$appId == "" || $apiKey == "" || $email == "" || $password == "")
{
    exit(
"<pre>One or more required parameters are missing.<br /><br />" .
       
"Please open in this file in any text editor to fill all the required " .
       
"parameters and try again.</pre>");
}

/*
 * Show the upload form
 */
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
        <title>MediaFire API PHP Library - File Uploading</title>
    </head>
    <body>
        <form method="post" enctype="multipart/form-data" action="">
            <p>Upload a file to a MediaFire account:</p>
            <p>
                <label title="Choose a Local File to a MediaFire account" for="file">File:</label>
                <input type="file" id="file" name="file" size="30" />
                <input type="submit" id="upload" name="upload" value="Upload" />
            </p>
            <?php
           
if (isset($_POST["upload"]))
            {
               
/*
                 * Move uploaded file to current script folder and start uploading
                 */
               
$uploadedFile = "./" . basename($_FILES["file"]["name"]);

                if (
move_uploaded_file($_FILES["file"]["tmp_name"], $uploadedFile))
                {
                   
/*
                     * Initilize a new instance of the class
                     */
                   
include("../mflib.php");

                   
$mflib = new mflib($appId, $apiKey);
                   
$mflib->email = $email;
                   
$mflib->password = $password;

                   
/*
                     * Select a file to be uploaded. The third argurment of method fileUpload()
                     * is the quickkey of the destination folder. In this case it's omitted, which
                     * means the file will be stored in the root folder - 'My files'
                     */
                   
$sessionToken = $mflib->userGetSessionToken();
                   
$uploadKey = $mflib->fileUpload($sessionToken, $uploadedFile);
                }

               
/*
                 * Print the upload result
                 */
               
if ($uploadKey)
                {
                   
var_dump($mflib->filePollUpload($sessionToken, $uploadKey));
                }
            }
           
?>
</form>
    </body>
</html>