How to change
filename in file upload using Web::instance()?$file['name'] = "newfilename"
; doesn't work.
$f3->set('UPLOADS','uploads/'); // don't forget to set an Upload directory, and make it writable!
$overwrite = false; // set to true, to overwrite an existing file; Default: false
$slug = true; // rename file to filesystem-friendly version
$files = $web->receive(function($file){
var_dump($file);
/* looks like:
array(5) {
["name"] => string(19) "csshat_quittung.png"
["type"] => string(9) "image/png"
["tmp_name"] => string(14) "/tmp/php2YS85Q"
["error"] => int(0)
["size"] => int(172245)
}
*/
// $file['name'] already contains the slugged name now
// maybe you want to check the file size
if($file['size'] > (2 * 1024 * 1024)) // if bigger than 2 MB
return false; // this file is not valid, return false will skip moving it
// everything went fine, hurray!
return true; // allows the file to be moved from php tmp dir to your defined upload dir
},
$overwrite,
$slug
);
Parameter 1 to {closure}() expected to be a reference, value given
code:$files = $web->receive(function(&$file){
[...]$file['name'] = "newfilename"
;
function(&$file) {}