In our application, we implemented the file upload for each module. What we have done right now is the file will save depends on the module.
Example we have 3 modules:
1) Module A 2) Module B 3) Module C
when the user uploaded a file in Module A. It will look like this
// Assuming your company id is 11
public/attachments/11/Module A/filename.fileextension
If user uploaded another file in Module B
// Company id is still 11
public/attachments/11/Module B/filename.fileextension
Now this is what we want, we want to get the total size of each extension then display it in our view
Example
Attachment Uploaded Size:
Images: 900 KB
Docs/x: 250 MB
PDF: 100 KB
Controller
/* =========================== GET ALL UPLOADED FILES =========================== */
$all_attachments = CustomerModel::getAllAttachments();
if($all_attachments)
{
$docs_size = 0;
foreach($all_attachments as $key => $file)
{
/* === FILE NAME === */
$filename = $file->filename;
/* === FILE EXTENSION === */
$extension = \File::extension($filename);
if($extension == 'docx' || $extension == 'doc')
{
// dd("sss");
$docs_size += $file->size();
}
// dd($foo);
// $file =
// dd($file->getClientOriginalExtension());
}
}
Attachment Files table
ID
Module Type(string)
File name(string)
Question: Is it possible to sum all the same file extension?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire