Mediafire PHP File Uploading and Get Link Example
When i was working on my project i need to use mediafire API for uploading image and video, I did see this API is little hard to undestand but it is pretty easy to use also. In this post i want to share example how to get link of uploaded image or video. If you are new and you need to example for uploading example then it is very simple example that way you can undestand very well. I also see other example from google search but that was very difficult to undestand and use too.
So ,first you should need to download mflib.php file for Mediafire API. so if you dan't have this file then you can downlaod from here: mflib.php. Now you have to just create one file in your root directory and 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);
}
?>
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to get HTML Tag Attribute Value in PHP?
- PHP MySQL Image Gallery CRUD Example
- PHP Bootstrap Autocomplete Tokenfield using Ajax Example
- How to Integrate Google Map using Gmaps JS?
- How to Remove Duplicate Values from Array in PHP?
- How to Get File Name without Extension in PHP?
- How to Remove White Space from String in PHP?
- How to Increase Upload File Size Limit PHP in Ubuntu?
- How to Check If String is URL or Not in PHP?
- How to Convert Array Values to Lowercase in PHP?
- How to Count Number of Files in a Directory in PHP?
- How to Find Day Name from Specific Date in PHP?
- How to Remove Null Values from Array in PHP?