fix pictures 5
This commit is contained in:
@@ -51,7 +51,21 @@ class FileController extends Controller
|
|||||||
$file_name = $file_name_src.'.'.$data['ext'];
|
$file_name = $file_name_src.'.'.$data['ext'];
|
||||||
$data['has_thumb'] = false;
|
$data['has_thumb'] = false;
|
||||||
$data['size'] = $uploaded->getSize();
|
$data['size'] = $uploaded->getSize();
|
||||||
Storage::disk('public')->putFileAs($path, $uploaded, $file_name);
|
$stored = Storage::disk('public')->putFileAs($path, $uploaded, $file_name);
|
||||||
|
if (! $stored) {
|
||||||
|
return response()->json(['message' => 'ذخیره فایل روی سرور ناموفق بود'], 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
$storageFile = storage_path('app/public/'.$path.'/'.$file_name);
|
||||||
|
$publicFile = public_path('storage/'.$path.'/'.$file_name);
|
||||||
|
if (! is_file($publicFile) && is_file($storageFile)) {
|
||||||
|
$publicDir = dirname($publicFile);
|
||||||
|
if (! is_dir($publicDir)) {
|
||||||
|
mkdir($publicDir, 0755, true);
|
||||||
|
}
|
||||||
|
@copy($storageFile, $publicFile);
|
||||||
|
}
|
||||||
|
|
||||||
$data['src'] = 'storage/'.$path.'/'.$file_name;
|
$data['src'] = 'storage/'.$path.'/'.$file_name;
|
||||||
$data['user_id'] = auth()->id();
|
$data['user_id'] = auth()->id();
|
||||||
$data['sts'] = 1;
|
$data['sts'] = 1;
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||||
|
|
||||||
|
class PublicStorageController extends Controller
|
||||||
|
{
|
||||||
|
public function show(Request $request, string $path): BinaryFileResponse
|
||||||
|
{
|
||||||
|
$path = $this->sanitizeRelativePath($path);
|
||||||
|
if ($path === '') {
|
||||||
|
abort(404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$fullPath = $this->resolveReadablePath($path);
|
||||||
|
if ($fullPath === null) {
|
||||||
|
abort(404);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->file($fullPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function sanitizeRelativePath(string $path): string
|
||||||
|
{
|
||||||
|
$path = str_replace('\\', '/', $path);
|
||||||
|
$path = ltrim($path, '/');
|
||||||
|
|
||||||
|
if ($path === '' || str_contains($path, '..')) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function resolveReadablePath(string $path): ?string
|
||||||
|
{
|
||||||
|
foreach ($this->candidatePaths($path) as $fullPath) {
|
||||||
|
if (is_file($fullPath) && is_readable($fullPath)) {
|
||||||
|
return $fullPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<string>
|
||||||
|
*/
|
||||||
|
private function candidatePaths(string $path): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
storage_path('app/public/'.$path),
|
||||||
|
public_path('storage/'.$path),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use App\Http\Controllers\PublicStorageController;
|
||||||
use App\Models\Customer;
|
use App\Models\Customer;
|
||||||
use App\Models\Product;
|
use App\Models\Product;
|
||||||
use App\Services\ProductPriceService;
|
use App\Services\ProductPriceService;
|
||||||
@@ -15,6 +16,10 @@ use App\Http\Controllers\pay\PaymanController;
|
|||||||
use App\Models\Message;
|
use App\Models\Message;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
// وقتی public/storage symlink نیست یا فایل تازه فقط در storage/app/public است
|
||||||
|
Route::get('storage/{path}', [PublicStorageController::class, 'show'])
|
||||||
|
->where('path', '.*');
|
||||||
|
|
||||||
Route::get('/refPricer', function () {
|
Route::get('/refPricer', function () {
|
||||||
$ok = app(\App\Services\ProductPriceSyncService::class)->syncAll(true);
|
$ok = app(\App\Services\ProductPriceSyncService::class)->syncAll(true);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user