forked from projects/fipamo
ro
36d04c8f68
service classes are beginning to swell as there functionality is being fleshed out, so a new organizational structure was needed to make sure class sizes don't become too large and to increase site managability and legibilty as more features get added and the code base grows. data is for retrieving, managing site information, assets interact with external files and upkeep is for maintenance. some additional tweaks were also made to the options menu template to prep it for it's transition to a toolbar component
74 lines
2.5 KiB
PHP
74 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Assets;
|
|
|
|
class FileUploadService
|
|
{
|
|
public function __construct()
|
|
{
|
|
}
|
|
|
|
public static function handleFile($request, $type = null)
|
|
{
|
|
//$options = $request->getParsedBody();
|
|
//front end sends one by one for progress tracking, so grab first
|
|
$file = $request->file('upload_files');
|
|
$type = $file[0]->extension();
|
|
$public_path = '../public';
|
|
$filesPath = '';
|
|
$path = date('Y') . '/' . date('m');
|
|
$response = [];
|
|
switch ($type) {
|
|
case 'jpeg':
|
|
case 'jpg':
|
|
case 'png':
|
|
case 'gif':
|
|
if (isset($options["source"])) {
|
|
if ($options["source"] == "avatar-upload") {
|
|
$filesPath = '/assets/images/user/' . $path . '/';
|
|
//Member::updateData('avi', $filesPath . $file->getClientFileName());
|
|
} else {
|
|
$filesPath = '/assets/images/user/' . $path . '/';
|
|
// Settings::updateGlobalData('background', $filesPath . '/' . $file->getClientFileName());
|
|
}
|
|
} else {
|
|
$filesPath = '/assets/images/blog/' . $path . '/';
|
|
}
|
|
|
|
break;
|
|
case 'mkv':
|
|
case 'mp4':
|
|
$filesPath = '/assets/video/blog/' . $path . '/';
|
|
break;
|
|
case 'ogg':
|
|
case 'mp3':
|
|
$filesPath = '/assets/sound/blog/' . $path . '/';
|
|
break;
|
|
case 'pdf':
|
|
case 'txt':
|
|
case 'rtf':
|
|
$filesPath = '/assets/docs/blog/' . $path . '/';
|
|
break;
|
|
}
|
|
try {
|
|
// if does not exist, so lets create it.
|
|
if (!is_dir($public_path . $filesPath)) {
|
|
mkdir($public_path . $filesPath, 0755, true);
|
|
}
|
|
$filename = urlencode($file[0]->getClientOriginalName());
|
|
$file[0]->move($public_path . $filesPath, $filename);
|
|
} catch (RuntimeException $e) {
|
|
echo 'ERROR ' . $e->getMessage();
|
|
}
|
|
|
|
$response = [
|
|
'message' => "File Uploaded. Great!",
|
|
"filePath" => $filesPath . urlencode($file[0]->getClientOriginalName()),
|
|
"fileName" => urlencode($file[0]->getClientOriginalName()),
|
|
'type' => $type,
|
|
];
|
|
|
|
return $response;
|
|
}
|
|
}
|