Added ability to upload a file to a module with no breaking changes
Minor fix - removed double use of '../public' being added to 'destination' path.
Inbound variables
Unchanged 'destination' path - as before or you can specify the path you want (note:path must exist, or an error will be thrown). This is the only inbound variable that needs to be set, the ones below default to false and can be omitted from your code.$config['destination'] = '../public/files'; //upload the file to public/files
Unchanged 'make_rand_name' - default is false - if true, file name is changed to a random string
$config['upload_to_module'] = true;
Added 'target_module' - default is the current module via the first segment of the URL or you can enter the name of another module
$config['target_module'] = 'members'; //upload file to members/assets
Added 'upload_to_module' - default is false, if true file will be uploaded to '_{modulename}/assets'.
$config['upload_to_module'] = true;
Example1 - upload file to 'public/files' folder, keeping the name of the original file
Upload_file.php - Enhanced
Inbound variables
$config['destination'] = '../public/files'; //upload the file to public/files
$config['upload_to_module'] = true;
$config['target_module'] = 'members'; //upload file to members/assets
$config['upload_to_module'] = true;
Example1 - upload file to 'public/files' folder, keeping the name of the original file
// upload Ahoy!
$config['destination'] = '../public/files';
$file_info = $this->upload_file($config);
Example2 - upload file to 'public/files' folder, changing the name to a random string
// upload Ahoy!
$config['destination'] = '../public/files';
$config['make_rand_name'] = true;
$file_info = $this->upload_file($config);
Example3 - upload file to the calling module's assets folder and into 'files' folder
// upload Ahoy!
$config['destination'] = 'files';
$config['upload_to_module'] = true;
$file_info = $this->upload_file($config);
Example4 - upload file to the 'members' module 'asset' folder and into 'files' folder with a random name
// upload Ahoy!
$config['destination'] = 'files';
$config['target_module'] = 'members';
$config['upload_to_module'] = true;
$config['make_rand_name'] = true;
$file_info = $this->upload_file($config);
Tested and working on PHP 8.0.xx, 8.1.xx and 8.2.00