1. Go to this page and download the library: Download initphp/upload 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/ */
initphp / upload example snippets
use InitPHP\Upload\Upload;
use InitPHP\Upload\File;
use InitPHP\Upload\Adapters\LocalAdapter;
$adapter = new LocalAdapter([
'dir' => __DIR__ . '/uploads/',
'url' => 'https://example.com/uploads/',
], [
'allowed_extensions' => ['jpg', 'jpeg', 'png', 'webp'],
'allowed_max_size' => 2 * 1024 * 1024, // 2 MB, in bytes
]);
$upload = new Upload($adapter);
foreach (File::setPost('photos') as $file) {
$stored = $upload->setFile($file)->to();
if ($stored !== false) {
echo 'Uploaded to: ' . $stored->getURL();
}
}
$file->rename('profile'); // keeps the original extension
$upload->setFile($file)->to(); // stored as profile.jpg
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.