PHP code example of almhdy / async-file-uploader

1. Go to this page and download the library: Download almhdy/async-file-uploader library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

almhdy / async-file-uploader example snippets



AsyncFileUploader\AsyncFileUploader;

$uploadDir = 'uploads'; // Specify your upload directory
$allowedTypes = ["image/jpeg", "image/png", "application/pdf"]; // Allowed file types
$maxFileSize = 2 * 1024 * 1024; // Set max file size to 2MB

$uploader = new AsyncFileUploader($uploadDir, $allowedTypes, $maxFileSize);
$response = $uploader->upload();

if (isset($response['error'])) {
    echo "Error: " . $response['error'];
} else {
    echo "File uploaded successfully! 🎉 Path: " . $response['path'];
}

$uploadDir = 'your/custom/directory'; // Set your custom upload directory

$allowedTypes = ["image/jpeg", "image/png", "application/pdf"];

$maxFileSize = 2 * 1024 * 1024; // Set max file size to 2MB