PHP code example of ramonztro / simple-upload-handler
1. Go to this page and download the library: Download ramonztro/simple-upload-handler 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/ */
ramonztro / simple-upload-handler example snippets
use RamonK\SimpleUploadHandler\SimpleUploadHandler;
//Creates a SimpleUploadHandler
$handler = new SimpleUploadHandler();
$i = 0;
//Navigates through files
while($handler->haveFiles()) {
try {
//Checks extension and errors
$handler->checkFile('jpg', 'jpeg', 'gif', 'png');
} catch (Exception $e) {
//Handles errors
die($e->getMessage());
}
try {
//Move current file to a directory
//(File extension is kept)
$handler->move('directory/wanted/', 'optional_new_name_' . $i++);
//Displays full filename (directory + basename)
echo $handler->getFileName();
//Displays basename (no directory path)
echo $handler->getBaseName();
//Displays other available information
echo $handler->getDirectory();
echo $handler->getExtension();
echo $handler->getSize();
echo $handler->getType();
} catch (Exception $e) {
//Handles errors
die($e->getMessage());
}
}