Demonstrates configuring and processing file uploads using FileUploader and UploadedFile.
- Setting the upload directory and allowed file extensions
- Adding/removing extensions with
addExt(),addExts(),removeExt() - Setting the HTML form input name with
setAssociatedFileName() - Checking the PHP max upload size with
FileUploader::getMaxFileSize() - Simulating uploads in CLI with
FileUploader::addTestFile()(useful for testing) - Processing uploads as
UploadedFileobjects withuploadAsFileObj() - Inspecting upload results:
isUploaded(),isReplace(),getUploadError()
In a real application, the uploader processes files from an HTML form:
<form method="POST" enctype="multipart/form-data" action="upload.php">
<input type="file" name="user_files" multiple>
<button type="submit">Upload</button>
</form>The name attribute of the file input must match the value set via setAssociatedFileName().
FileUploader— Configures and executes file uploads with extension validation.UploadedFile— ExtendsFilewith upload-specific properties (isUploaded(),isReplace(),getUploadError()).
php examples/file-upload.phpNote: This example uses
addTestFile()to simulate an upload in CLI mode. TheDSconstant (directory separator) must be defined, which the example handles automatically.