ItSolutionStuff.com

Mediafire PHP File Uploading and Get Link Example

By Hardik Savani • May 14, 2024
PHP Mediafire API

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);

}


?>

Tags: PHP
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to get HTML Tag Attribute Value in PHP?

Read Now →

PHP MySQL Image Gallery CRUD Example

Read Now →

PHP Bootstrap Autocomplete Tokenfield using Ajax Example

Read Now →

How to Integrate Google Map using Gmaps JS?

Read Now →

How to Remove Duplicate Values from Array in PHP?

Read Now →

How to Get File Name without Extension in PHP?

Read Now →

How to Remove White Space from String in PHP?

Read Now →

How to Increase Upload File Size Limit PHP in Ubuntu?

Read Now →

How to Check If String is URL or Not in PHP?

Read Now →

How to Convert Array Values to Lowercase in PHP?

Read Now →

How to Count Number of Files in a Directory in PHP?

Read Now →

How to Find Day Name from Specific Date in PHP?

Read Now →

How to Remove Null Values from Array in PHP?

Read Now →