Implement Drag‑and‑Drop File and Directory Upload with trzsz in the Browser
This guide explains how to enable Windows cmd/PowerShell support, directory upload/download commands, and drag‑and‑drop file or folder uploading in a web page using trzsz/trzsz‑go, including the required server setup and a JavaScript code example.
The article introduces trzsz (or trzsz‑go) as a tool that supports Windows local terminals such as cmd and PowerShell, and provides commands for uploading directories ( trz -d ) and downloading files ( tsz -d xxx ).
It demonstrates that files and entire directories can be dragged directly onto a web page and uploaded to the server. By adding a small JavaScript snippet to the page, the drag‑over and drop events are handled, the default browser behavior is prevented, and the selected items are passed to trzszFilter.uploadFiles for transfer.
terminalHtmlElement.addEventListener("dragover", (event) => event.preventDefault());
terminalHtmlElement.addEventListener("drop", (event) => {
event.preventDefault();
trzszFilter
.uploadFiles(event.dataTransfer.items)
.then(() => console.log("upload success"))
.catch((err) => console.log(err));
});To make the upload work, the server must have trz or trzsz-go installed and the executable placed in a directory listed in the system PATH .
After following these steps, users can conveniently transfer files and folders from their browsers to the server with a simple drag‑and‑drop interface.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.