芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/kwesioben.com/paymoney/app/helpers/files.php
true, 'message' => __('File uploaded successfully.') ]; $path = makeDirectory($location); if (!$path) { $response = [ 'status' => false, 'message' => __('Directory could not been created.'), ]; } if ($thumb){ $thumbPath = makeDirectory($location . '/thumb/'); if (!$thumbPath) { $response = [ 'status' => false, 'message' => __('Thumb direcotry could not been created.'), ]; } } if (!empty($old)) { removeFile($location . '/' . $old); removeFile($location . '/thumb/' . $old); } try { $filename = time() . '.' . $file->getClientOriginalExtension(); $image = \Intervention\Image\Facades\Image::make($file); if (!empty($size)) { $size = explode('*', strtolower($size)); $image->resize($size[0], $size[1]); } $image->save($location . '/' . $filename); if (!empty($thumb)) { $thumb = explode('*', $thumb); \Intervention\Image\Facades\Image::make($file)->resize($thumb[0], $thumb[1])->save($location . '/thumb/' . $filename); } $response['file_name'] = $filename; } catch (\Exception $e) { $response = [ 'status' => false, 'message' => $e->getMessage() ]; } return $response; } } if (!function_exists('makeDirectory')) { /** * making directory * * @param string $path * @param int $permission * * @return bool */ function makeDirectory($path, $permission = null) { if (file_exists($path)) { return true; } $permission = !empty($permission) ? $permission : config('file_permission', 0755); return mkdir($path, $permission, true); } } if (!function_exists('removeFile')) { /** * making directory * * @param string $path * * @return bool */ function removeFile($path) { return file_exists($path) && is_file($path) ? @unlink($path) : false; } } if (!function_exists('generatePDF')) { function generatePDF($view, $fileName, $data) { $mpdf = new \Mpdf\Mpdf(['tempDir' => __DIR__ . '/tmp']); $mpdf = new \Mpdf\Mpdf([ 'mode' => 'utf-8', 'format' => 'A4', 'orientation' => 'P', ]); $mpdf->autoScriptToLang = true; $mpdf->autoLangToFont = true; $mpdf->allow_charset_conversion = false; $mpdf->WriteHTML(view($view, $data)); $mpdf->Output($fileName . time() . '.pdf', 'I'); } } if (!function_exists('logoPath')) { function logoPath() { return !empty(settings('logo')) && file_exists(public_path('uploads/logos/' . settings('logo'))) ? asset('public/uploads/logos/' . settings('logo')) : asset('public/dist/images/default-logo.png'); } } if (!function_exists('getSystemLogo')) { function getSystemLogo($className = 'logo-size') { return '
'; } } if (!function_exists('faviconPath')) { function faviconPath() { return image(settings('favicon'), 'favicon'); } } if (!function_exists('image')) { /** * Get the image resource * * @param string|null $imageName * @param string $directoryName * @return string */ function image(?string $imageName, ?string $directoryName): string { if (empty($imageName)) { return defaultImage($directoryName); } $imageFullPath = getDirectory(strtolower($directoryName)) . $imageName; if (file_exists(base_path($imageFullPath))) { return asset($imageFullPath); } return defaultImage($directoryName); } } if (!function_exists('defaultImage')) { /** * defaultImage * * @param mixed $type * @return string */ function defaultImage(?string $type): string { $defaultImages = [ 'logo' => 'public/dist/images/default-logo.png', 'favicon' => 'public/dist/images/default-favicon.png', 'profile' => 'public/dist/images/default-avatar.png', 'merchant' => 'public/dist/images/default-merchant.png', 'currency' => 'public/dist/images/default-currency.png', 'crypto' => 'public/dist/images/gateways/crypto.png', 'bank' => 'public/dist/images/bank.png', 'stripe' => 'public/dist/images/gateways/stripe.png', 'mts' => 'public/dist/images/gateways/mts.png', 'paypal' => 'public/dist/images/gateways/paypal.png', 'bank' => 'public/dist/images/gateways/bank.png', 'payumoney' => 'public/dist/images/payumoney.png', 'payeer' => 'public/dist/images/payeer.png', 'coinpayments' => 'public/dist/images/gateways/coinpayments.png', 'coinpayments_ipn' => 'public/dist/images/coinpayments_ipn.png', 'language_flag' => 'public/dist/images/default-flag.png', 'error' => 'public/dist/images/alert/error.png', 'warning' => 'public/dist/images/alert/warning.png', 'success' => 'public/dist/images/alert/checked.png', 'fail' => 'public/dist/images/failed.svg', 'loader' => 'public/dist/images/loader.gif', 'notfound' => 'public/dist/images/not-found.png', 'referral_award' => 'Modules/Referral/Resources/assets/referral.png', 'investment' => 'Modules/Investment/Resources/assets/investment.png' ]; return array_key_exists(strtolower($type), $defaultImages) ? asset($defaultImages[strtolower($type)]) : asset('public/dist/images/default-img.png'); } } if (!function_exists('getDirectory')) { /** * directory * * @param mixed $type * @return string */ function getDirectory(string $directoryName): string { $directories = [ 'logo' => 'public/uploads/logos/', 'favicon' => 'public/uploads/logos/', 'currency' => 'public/uploads/currency_logos/', 'profile' => 'public/uploads/user-profile/', 'merchant' => 'public/uploads/merchant/', 'user_qrcode' => 'public/uploads/qrcode/user/', 'merchant_qrcode' => 'public/uploads/qrcode/merchant/', 'language_flag' => 'public/uploads/languages-flags/', 'bank_logos' => 'public/uploads/files/bank_logos/', ]; if (!is_dir($directories[$directoryName])) { makeDirectory($directories[$directoryName]); } return $directories[$directoryName] ?? ''; } } if (!function_exists('checkFileValidation')) { function checkFileValidation($ext, $type = 0) { return in_array(strtolower($ext), getFileExtensions($type)) ? true : false; } } if (!function_exists('getFileExtensions')) { function getFileExtensions($type = 0) { $extensions = array( 0 => ['jpg', 'jpeg', 'png', 'bmp', 'gif', 'doc', 'docx', 'xls', 'xlsx', 'csv', 'pdf'], 1 => ['jpg', 'jpeg', 'png', 'gif', 'doc', 'docx', 'pdf'], 2 => ['jpg', 'jpeg', 'png', 'doc', 'docx', 'pdf'], 3 => ['jpg', 'jpeg', 'png', 'gif', 'bmp'], 4 => ['ico'], 5 => ['doc', 'docx', 'xls', 'xlsx', 'csv', 'pdf'], 6 => ['jpg', 'jpeg', 'png'], 7 => ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'ico'], 8 => ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'pdf'] ); return $extensions[$type]; } } if (!function_exists('maxFileSize')) { /** * maxFileSize * @param int $fileSize * @return string */ function maxFileSize($fileSize) { $data = []; $maxfileSize = preference('file_size'); if (isset($maxfileSize) && !empty($maxfileSize)) { $maxFileSize = (int) $maxfileSize; if (($fileSize / 1024) <= $maxfileSize * 1024) { $data['status'] = 1; } else if (($fileSize / 1024) > $maxfileSize * 1024) { $data['status'] = 0; $data['message'] = __('Maximum File Size :x MB.', ['x' => $maxfileSize]); } return $data; } } } if (!function_exists('fileExistCheck')) { /** * Check if the file exist in the correct location * @param $file [filename from database or request] * @param $path [path key that define in getDirectory() function] * @return string|bool */ function fileExistCheck($file, $path): string|bool { if (!is_null($file)) { $file = base_path(getDirectory($path) . '/' . $file); if (file_exists($file)) { return $file; } } return false; } } if (!function_exists('svgIcons')) { /** * Get the svg icon * * @param string $name * @return string */ function svgIcons(string $name) { $icons = [ 'right_angle' => '
', 'left_angle' => '
', 'stepper_create' => '
', 'stepper_confirm' => '
', 'stepper_success' => '
', 'arrow_right_left' => '
', 'arrow_right_left_lg' => '
', 'printer_sm' => '
', 'printer' => '
', 'wallet_arrow_up' => '
', 'wallet_arrow_down' => '
', 'edit_icon' => '
', 'edit_icon_lg' => '
', 'edit_icon_background' => '
', 'delete_icon' => '
', 'delete_icon_lg' => '
', 'camera_icon' => '
', 'scanner_icon' => '
', 'scanner_icon_sm' => '
', 'lock' => '
', 'envalop' => '
' , 'gear_icon' => '
', 'eye_open_icon' => '
', 'eye_cross_icon' => '
', 'cross_icon' => '
', 'copy_icon' => '
', 'copy_bg_icon' => '
', 'download_icon' => '
', 'ticket_icon' => '
', 'dot_icon' => '
', 'right_angle_sm' => '
', 'left_angle_sm' => '
', 'right_angle_md' => '
', 'sun' => '
', 'moon' => '
' ]; return $icons[$name]; } } if (!function_exists('menuSvgIcon')) { /** * Get the sidebar menu svg icon * * @param string $routeName * @return string */ function menuSvgIcon(string $routeName) { $activeColor = request()->route()->named($routeName) ? '#FFAF30' : '#C1BFDF'; $icons = [ 'dashboard' => '
', 'transactions' => '
', 'wallets' => '
', 'deposit' => '
', 'send_money' => '
', 'request_money' => '
', 'exchange_money' => '
', 'withdrawal' => '
', 'merchants' => '
', 'disputes' => '
', 'tickets' => '
', 'profiles' => '
', 'setting' => '
', 'crypto_buy_sell' => '
' ]; return $icons[explode('.', $routeName)[1]]; } }