UploadFolder
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.
Install / Use
/learn @komputronika/UploadFolderREADME
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
- Download or clone this repo
- Put the script on your web server's document root
- Open that folder in browser, eg: http://yourweb/uploadfolder/
Package Content
- HTML file that contain input element and user interfaces.
- CSS file for styling.
- Javascript file for handling file input and send request to server.
- PHP file that accept file from client and save file in server.
Screenshot
<a href="https://imgur.com/bCUHbvv"><img src="https://i.imgur.com/bCUHbvv.png" title="source: imgur.com" /></a>
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
Related Skills
node-connect
345.9kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
106.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
345.9kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
345.9kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
