Download the PHP package lithemod/upload without Composer
On this page you can find all versions of the php package lithemod/upload. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lithemod/upload
More information about lithemod/upload
Files in lithemod/upload
Package upload
Short Description A versatile module for efficiently managing file uploads in PHP, ensuring seamless integration and robust error handling.
License MIT
Informations about the package upload
Upload
A simple PHP module for handling file uploads with ease.
Installation
You can easily install the Upload module using Composer. Run the following command:
Usage
Here's a basic example of how to use the Upload
module after installation:
-
Handling File Uploads: Create an HTML form for file uploads:
- Processing the Upload:
In your
upload.php
, use theUpload
class to handle the file:
Methods
__construct(array $file)
- Initializes the upload instance with the file data.
move(string $uploadDir, ?array $allowedExtensions = null): ?string
- Moves the uploaded file to the specified directory.
- Generates a unique filename to avoid overwriting.
- Optionally validates the file extension against allowed extensions.
isUploaded(): bool
- Checks if a file is successfully uploaded.
getMimeType(): ?string
- Retrieves the MIME type of the uploaded file.
getSize(): ?int
- Retrieves the size of the uploaded file in bytes.
Error Handling
The module throws exceptions for various error scenarios, including:
- Invalid file upload array
- Upload directory does not exist or is not writable
- File extension not allowed
Make sure to wrap the usage of the module in try-catch blocks to handle exceptions appropriately.
License
This module is licensed under the MIT License. See the LICENSE file for more information.