Editor Info - thepoopooman652/proishs-webtools GitHub Wiki
This folder implements a single-page web-based file editor with a front-end UI and a server-side JSON API. The editor provides a file list view, text editing (CodeMirror), file upload, file creation, file deletion (soft-delete), and binary file streaming for media types.
-
index.php— Front-end UI. Uses CodeMirror for editing text files and includes client-side logic to display a file tree, handle uploads, and stream binary files. The UI supports single- and multi-file uploads and inline viewing of images, audio, video, and PDFs. -
api.php— Server-side router exposing JSON endpoints and binary streaming behavior. Implemented actions includelist-files,get-content,create-file,save-file,upload-file, anddelete-file. -
files/— Storage area containing shared files and per-user folders. The default configured base directory is__DIR__ . '/files/'.
GET api.php?action=list-files
- Returns a JSON object with
files(array) anduser_ip. - Each file entry contains:
name,path,size(bytes),type(MIME type), andreadonly(boolean).
GET api.php?action=get-content&path=<path>
- For text-like files returns JSON:
{
"success": true,
"content": "...",
"mime": "text/plain"
}- For binary files the endpoint streams the file with the appropriate
Content-TypeandContent-Lengthheaders.
POST api.php?action=create-file
- Parameters:
filename(string). Creates an empty file under the caller's directory and returns a JSON success message withpath.
POST api.php?action=save-file
- Parameters:
path,content. Writescontentto the resolved path and returns a JSON status object.
POST api.php?action=upload-file
- Multipart field:
uploadedFile. Accepts an uploaded file and moves it into the caller's folder. Returns JSON with operation status.
POST api.php?action=delete-file
- Parameters:
path. Performs a soft delete by moving the file into adeleted-files/subfolder with a timestamped name and returns a JSON status object.
- File paths returned by
list-filesuse either the root path (for shared files) oruser_ip/filenamefor per-user entries. - MIME types are derived via
mime_content_type()when available; empty files are labeledtext/plain.
Fetch file list (browser):
fetch('api.php?action=list-files')
.then(r => r.json())
.then(data => console.log(data.files));Save a file (client):
const form = new FormData();
form.append('path', '127.0.0.1/myfile.txt');
form.append('content', 'New content');
fetch('api.php?action=save-file', { method: 'POST', body: form })
.then(r => r.json())
.then(res => console.log(res));- The front-end in
index.phpuses CodeMirror modes to determine editing behavior based on MIME type; mode detection is performed withCodeMirror.findModeByMIME(). - The server-side
get_safe_path()function canonicalizes and validates file paths; it resolves paths usingrealpath()and only accepts files within the configuredFILES_BASE_DIRor the per-user directory. - Per-user folders follow the pattern
files/<REMOTE_ADDR>/by default. Alternate user identification mechanisms can be used by adapting the server-side code responsible foruser_dircomputation.
Run the built-in PHP server from the editor directory to exercise the UI and API locally:
cd 'C:\Users\Administrator\Documents\GitHub\proish-webtools\editor'
php -S 127.0.0.1:8000 -t .Open http://127.0.0.1:8000/index.php and exercise: file listing, open/save of text files, uploads, and viewing of media files.
- 2025-11-06: Documented API contract, client usage examples, and developer guidance for path resolution and client integration.
This README provides a reference for integrating with the editor UI and server-side API and documents the expected request/response shapes for programmatic interaction.