If you send multiple files or only one, there is a array
that informs the generated names that has the chave
%:%
Specific location in the example code:
if($data['isComplete']){
$files = $data['data'];
foreach($files['metas'] as $values)
{
//aqui são os nomes gerados
echo $values['name'];
}
}
that is, name
use to write to your database.
In addition to the name of the generated file has several information:
Array
(
[files] => Array
(
[0] => uploads/Lh3EGOrl7D.jpg
[1] => uploads/nJVhvxBXQD.jpg
[2] => uploads/0kJOf_ABQt.jpg
[3] => uploads/lH9ZrpGAbM.jpg
)
[metas] => Array
(
[0] => Array
(
[date] => Thu, 06 Oct 2016 17:15:00 -0300
[extension] => jpg
[file] => uploads/Lh3EGOrl7D.jpg
[name] => Lh3EGOrl7D.jpg
[old_name] => 14064104_10209380587605927_5793335061447087469_n.jpg
[replaced] =>
[size] => 8251
[size2] => 8.06 KB
[type] => Array
(
[0] => image
[1] => jpeg
)
)
[1] => Array
(
[date] => Thu, 06 Oct 2016 17:15:00 -0300
[extension] => jpg
[file] => uploads/nJVhvxBXQD.jpg
[name] => nJVhvxBXQD.jpg
[old_name] => 14192672_1402374739778600_7123746786432954771_n.jpg
[replaced] =>
[size] => 14404
[size2] => 14.07 KB
[type] => Array
(
[0] => image
[1] => jpeg
)
)
as extension, old filename, size, date of submission, etc. These key values can be used in $values['name']
if you want.
Full Code:
Html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
<link href="css/jquery.filer.css" type="text/css" rel="stylesheet" />
<link href="css/themes/jquery.filer-dragdropbox-theme.css" type="text/css" rel="stylesheet" />
<script src="//code.jquery.com/jquery-3.1.0.min.js"></script>
<script src="js/jquery.filer.min.js"></script>
</head>
<body>
<br>
<br>
<br>
<div class="flex-center position-ref full-height">
<div class="content">
<form action="upSave.php" method="post" enctype="multipart/form-data">
<input type="file" name="files[]" id="filer_input" multiple="multiple">
<input type="submit" value="Enviar">
</form>
</div>
</div>
<script>
$(document).ready(function() {
$('#filer_input').filer();
});
</script>
</body>
</html>
PHP
<?php
require_once("class.uploader.php");
$uploader = new Uploader();
$data = $uploader->upload($_FILES['files'], array(
'limit' => 10, //Maximum Limit of files. {null, Number}
'maxSize' => 10, //Maximum Size of files {null, Number(in MB's)}
'extensions' => null, //Whitelist for file extension. {null, Array(ex: array('jpg', 'png'))}
'required' => false, //Minimum one file is required for upload {Boolean}
'uploadDir' => 'uploads/', //Upload directory {String}
'title' => array('auto', 10), //New file name {null, String, Array} *please read documentation in README.md
'removeFiles' => true, //Enable file exclusion {Boolean(extra for jQuery.filer), String($_POST field name containing json data with file names)}
'replace' => false, //Replace the file if it already exists {Boolean}
'perms' => null, //Uploaded file permisions {null, Number}
'onCheck' => null, //A callback function name to be called by checking a file for errors (must return an array) | ($file) | Callback
'onError' => null, //A callback function name to be called if an error occured (must return an array) | ($errors, $file) | Callback
'onSuccess' => null, //A callback function name to be called if all files were successfully uploaded | ($files, $metas) | Callback
'onUpload' => null, //A callback function name to be called if all files were successfully uploaded (must return an array) | ($file) | Callback
'onComplete' => null, //A callback function name to be called when upload is complete | ($file) | Callback
'onRemove' => 'onFilesRemoveCallback' //A callback function name to be called by removing files (must return an array) | ($removed_files) | Callback
));
if($data['isComplete']){
$files = $data['data'];
//print_r($files);
foreach($files['metas'] as $values)
{
echo $values['name'];
echo '<br />';
}
}
if($data['hasErrors']){
$errors = $data['errors'];
print_r($errors);
}