Any Image I upload from my live website is not showing ... But is was working fine on localhost i have also done php artisan storage:link but the result is still the same . Images are being saved inside public folder
....
I have used this logic to save images
...
public function saveFiles(Request $request) {
$uploadPath = public_path(env('UPLOAD_PATH'));
$thumbPath = public_path(env('UPLOAD_PATH').'/thumb');
if (! file_exists($uploadPath)) {
mkdir($uploadPath, 0775);
mkdir($thumbPath, 0775);
}
$finalRequest = $request;
foreach ($request->all() as $key => $value) {
if ($request->hasFile($key)) {
if ($request->has($key . '_max_width') && $request->has($key . '_max_height')) {
// Check file width
$filename = time() . '-' . $request->file($key)->getClientOriginalName();
$file = $request->file($key);
$image = Image::make($file);
if (! file_exists($thumbPath)) {
mkdir($thumbPath, 0775, true);
}
Image::make($file)->resize(50, 50)->save($thumbPath . '/' . $filename);
$width = $image->width();
$height = $image->height();
if ($width > $request->{$key . '_max_width'} && $height > $request->{$key . '_max_height'}) {
$image->resize($request->{$key . '_max_width'}, $request->{$key . '_max_height'});
} elseif ($width > $request->{$key . '_max_width'}) {
$image->resize($request->{$key . '_max_width'}, null, function ($constraint) {
$constraint->aspectRatio();
});
} elseif ($height > $request->{$key . '_max_height'}) {
$image->resize(null, $request->{$key . '_max_height'}, function ($constraint) {
$constraint->aspectRatio();
});
}
$image->save($uploadPath . '/' . $filename);
$finalRequest = new Request(array_merge($finalRequest->all(), [$key => $filename]));
} else {
$filename = time() . '-' . $request->file($key)->getClientOriginalName();
$request->file($key)->move($uploadPath, $filename);
$finalRequest = new Request(array_merge($finalRequest->all(), [$key => $filename]));
}
}
}
return $finalRequest;
}
...
...
my config/filesystem.php
...
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL') . '/storage',
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => env('AWS_KEY'),
'secret' => env('AWS_SECRET'),
'region' => env('AWS_REGION'),
'bucket' => env('AWS_BUCKET'),
],
'uploads' => [
'driver' => 'local',
'root' => public_path('uploads'),
],
'uploads_test' => [
'driver' => 'local',
'root' => public_path('uploads/test')
],
],
Using this to show my pictures
<img src="{{ asset(env('UPLOAD_PATH').'/' . $room->display_image) }}"/>
I think it's because in local , public folder is in same directory with other folders of project (app-bootstrap-config-....) but in shared-host those project folders is not near of public folder (for ex. public_html)
You should set your public path in index.php that is in public
something like below code:
$app->bind('path.public', function() {
return __DIR__;
});