GithubHelp home page GithubHelp logo

komputronika / uploadfolder Goto Github PK

View Code? Open in Web Editor NEW
14.0 2.0 4.0 21 KB

This script is for uploading a folder to a server by maintaining the structure of that folder. Using pure PHP, HTML and Javascript without additional libraries.

HTML 16.44% JavaScript 31.82% CSS 10.09% PHP 41.65%
php javascript html input files upload googledrive folder recursively

uploadfolder's Introduction

Upload Folder

Pure Javascript, HTML and PHP without any library

This demo allows you to choose a folder via a standard HTML file input. All files (including nested files) inside that folder are added to the input's files list. This script using webkitdirectory attribute that compatible with browser Chrome, Edge or Firefox.

Choose a folder, and all files in that folder will be uploaded recursively (Inspiration came from Google Drive).

Supported browser: Chrome, Edge, Firefox, Android, Samsung and other browsers that support webkitdirectory attribut.

Installation

  1. Download or clone this repo
  2. Put the script on your web server's document root
  3. Open that folder in browser, eg: http://yourweb/uploadfolder/

Package Content

  1. HTML file that contain input element and user interfaces.
  2. CSS file for styling.
  3. Javascript file for handling file input and send request to server.
  4. PHP file that accept file from client and save file in server.

Screenshot

Core Codes

index.html

    <h3>Choose Folder</h3>
    <div class="picker"><input type="file" id="picker" webkitdirectory multiple></div>
    
    ...
    <script src="main.js"></script>

main.js

    // On button input change (picker), process it
    picker.addEventListener('change', e => {
        ...
        // Process every single file
        for (var i = 0; i < picker.files.length; i++) {
            var file = picker.files[i];
            sendFile(file, file.webkitRelativePath);
        }
    });

    // Function to send a file, call PHP backend 
    sendFile = function(file, path) {
        ...
        // Set post variables 
        formData.set('file', file); // One object file
        formData.set('path', path); // String of local file's path 
    
        // Do request
        request.open("POST", 'process.php');
        request.send(formData);
    
    };

process.php

    <?php
    require_once("include/upload.class.php");
    
    $up = new Upload();
    $up->set_folder("upload");
    $up->process($_POST["path"], $_FILES["file"]);
    ?>

Todo

  • Progress bar
  • Configurable Javascript
  • Composer style PHP class

uploadfolder's People

Contributors

komputronika avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.