[FREE] File Uploader : Upload files to server with PHP

File Uploader

This extension allows you to upload any type of file to your custom hosting like hostinger, 000webhost etc. This extension work on a simple 2KB php file that will be upload on your hosting file manager. You will get the php file with the extension.

Latest Version: 1.0
Released on: 01 November 2024
Updated on: 01 November 2024

All Blocks

{030AA6BA-FEC0-43B4-882A-541EA1220415}

Documentation

{9ED37E34-8B21-4796-9C99-A66D27DAEDA2}

This block uploads the file to the server.
uploadUrl: This is the URL of your PHP file.
fileName: The name of the uploaded file, you can leave this empty if you want to retain the original file name. It is recommended to use random file name here to avoid duplications.
filePath: Path of the file that you have to upload. Can be a selection of the image picker component.

image

This event will be triggered on the response from your server.
success: true if operation is successful else false
result: returns the file URL or the error.

Demo

Downloads

Both PHP script and extension will be downloaded as zip.

Open Source

PHP Script

<?php

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

    $target_dir = "upload/";
    $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);

    header("Content-Type: application/json");

    if (!file_exists($target_dir)) {
        mkdir($target_dir, 0777, true);
    }

    if (file_exists($target_file)) {
        showResult(false, "File with this name already exist");
    } else {
        if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
            $actual_link = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
            $actual_link = str_replace(basename($actual_link), $target_file, $actual_link);
            showResult(true, $actual_link);
            echo "The file " . htmlspecialchars(basename($_FILES["fileToUpload"]["name"])) . " has been uploaded.";
        } else {
            showResult(false, "Something went wrong");
        }
    }
}

function showResult($success, $message)
{
    $myObj = array(
        "success" => $success,
        "result" => $message,
    );
    $myJSON = json_encode($myObj);
    echo $myJSON;
    die();
}

You can modify the script as per you need like adding a secret key or a user id in order to avoid spamming.

Credit

Thanks @Shreyash for the super power full Rush .

Thanks you
Sumit​ :wink:

5 Likes

Welcome back :bouquet:
Another awesome extension from you :clap:

1 Like

Very good extension !

Nico

Nice solution, can be just as easily done with blocks alone...

4 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.