1. Go to this page and download the library: Download rundiz/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/ */
rundiz / upload example snippets
// You have to include/IRECTORY_SEPARATOR.'Rundiz'.DIRECTORY_SEPARATOR.'Upload'.DIRECTORY_SEPARATOR.'Upload.php';
if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
$Upload = new \Rundiz\Upload\Upload('filename');
$Upload->move_uploaded_to = '/path/to/your/uploaded-files';
// Allowed for gif, jpg, png
$Upload->allowed_file_extensions = array('gif', 'jpg', 'jpeg', 'png');
// Max file size is 900KB.
$Upload->max_file_size = 900000;
// Max image dimensions (width, height) in pixels. The array values must be integer only.
// Please note that this cannot check all uploaded files correctly. For example: You allowed to upload txt and jpg, the txt file will be pass validated for max dimension. To make it more precise, please check it again file by file after move uploaded files are completed done.
$Upload->max_image_dimensions = array(1280, 720);
// You can name the uploaded file to new name or leave this to use its default name. Do not '.htmlspecialchars(stripslashes(var_export($uploaded_data, true))).'</pre>';
}
// To check for the errors.
if (is_array($Upload->error_messages) && !empty($Upload->error_messages)) {
echo '<h3>Error!</h3>';
foreach ($Upload->error_messages as $error_message) {
echo '<p>'.$error_message.'</p>'."\n";
}// endforeach;
}
// To check for the errors and use your own text. (new in 2.0.1).
if (is_array($Upload->error_codes) && !empty($Upload->error_codes)) {
foreach ($Upload->error_codes as $errIndex => $errItem) {
if (isset($errItem['code'])) {
switch ($errItem['code']) {
case 'RDU_1':
echo 'You have uploaded the file that is larger than limit.';
break;
case 'RDU_xxx':
// See more in error_codes property to see its array format and all available error codes.
break;
}// endswitch;
}
}// endforeach;
}
// To use your translation from raw error message in this class. (new in 2.0.5).
if (is_array($Upload->error_messages) && !empty($Upload->error_messages)) {
echo '<h3>Error!</h3>';
foreach ($Upload->errorMessagesRaw as $error_message) {
if (isset($error_message['message']) && isset($error_message['replaces'])) {
echo '<p>'.vprintf(
gettext($error_message['message']), // this example use gettext to translate text.
$error_message['replaces']
).'</p>'."\n";
}
}// endforeach;
}
}