Mediafire PHP file uploading and get link example

Share Me
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Today now in this post i will talk with you about Mediafire PHP file uploading and get link example. When i was working on my office new project project i need to use mediafire API for uploading the image and video, here I was saw this API is little hard to understand but it is very easy to use also. Now in this post i want to share an example of how to get link of uploaded image or video. If you are new and if you need to example for uploading then i hope it is very simple example, On that way we can solve well. Here I also see other example from google search but that was more difficult to understand and use also.

So ,at first we should need to download mflib.php file for Mediafire API. So if you dan’t have this file then you can download the file from here: mflib.php. Now we need to just create one file in our root directory and need to put bellow code:

index.php

<?php


error_reporting(E_ALL);
ini_set('display_errors', 1);


require_once("../mflib.php");


$appId = "";
$apiKey = "";
$email = "";
$password = "";


?>


<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>PHP - MediaFire API Library - File Uploading With Get Link</title>
    </head>
    <body>
        <form method="post" enctype="multipart/form-data" action="">
            <p>Upload a file:</p>
            <label title="Choose a Local File to a MediaFire account" for="file">File:</label>
            <input type="file" id="file" name="file" size="30" />
            <div style="clear:left;display:block;" id="dvFile"></div>
            <input type="submit" id="upload" name="upload" value="Upload" />
        </form>
    </body>
</html>


<?php


if (isset($_POST['upload'])) {
    

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


    $uploadkey = $mflib->fileUpload($token, $_FILES["file"]["tmp_name"],"myfiles",$_FILES["file"]["name"]);
    $fileDetails = $mflib->filePollUpload($token, $uploadkey);
    $link = $mflib->fileGetLinks($fileDetails['quickkey'], "direct_download", $token);
   
 
    print_r($link);
}


?>

Read Also : How to convert Object into Array in PHP?

Thanks for read. I hope it help you. For more you can follow us on facebook.

About code chef

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by code chef →