1. Go to this page and download the library: Download zaszczyk/phalcon-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/ */
zaszczyk / phalcon-uploader example snippets
" "stanislav-web/phalcon-uploader": "1.*",
}
$loader->registerNamespaces([
'Uploader\Uploader' => 'path to src'
]);
$di->set('uploader', '\Uploader\Uploader');
if($this->request->hasFiles() !== false) {
// get uploader service
$uploader = $this->di->get('uploader');
// setting up uloader rules
$uploader->setRules([
'directory' => '/files',
//or 'dynamic' => '/files/'.$part.'/'.$userId, // added v1.4-beta
]);
// or use constructor if you don't use service
$uploader = new \Uploader\Uploader(([
'directory' => '/files',
//or 'dynamic' => '/files/'.$part.'/'.$userId, // added v1.4-beta
]);
}
if($this->request->hasFiles() !== false) {
// get uploader service or \Uploader\Uploader
$uploader = $this->di->get('uploader');
// setting up uloader rules
$uploader->setRules([
'directory' => '/files',
//or 'dynamic' => '/files/'.$part.'/'.$userId, // added v1.4-beta
'minsize' => 1000, // bytes
'maxsize' => 1000000,// bytes
'mimes' => [ // any allowed mime types
'image/gif',
'image/jpeg',
'image/png',
],
'extensions' => [ // any allowed extensions
'gif',
'jpeg',
'jpg',
'png',
],
'sanitize' => true // escape file & translate to latin
'hash' => 'md5' // save file as hash (default md5) you can use ANY function to handle filename
]);
}
if($this->request->hasFiles() !== false) {
// get uploader service or \Uploader\Uploader
$uploader = $this->di->get('uploader');
// setting up uloader rules
$uploader->setRules([
'directory' => '/files',
//or 'dynamic' => '/files/'.$part.'/'.$userId, // added v1.4-beta
'minsize' => 1000, // bytes
'maxsize' => 1000000,// bytes
'mimes' => [ // any allowed mime types
'image/gif',
'image/jpeg',
'image/png',
],
'extensions' => [ // any allowed extensions
'gif',
'jpeg',
'jpg',
'png',
],
'sanitize' => true
'hash' => 'md5'
]);
if($uploader->isValid() === true) {
$uploader->move(); // upload files array result
$uploader->getInfo() // var dump to see upload files
}
else {
$uploader->getErrors(); // var_dump errors
}
}
// you always can remove all files uploaded by one iteration
$uploader->truncate(); // added 1.1