0

I am working on a website that uploads images in sub dir, for example, every time the user uploads an image gets stored in storage/dropzone/upload/timestamp_date/image_name.jpg the problem I faced is the image is not showing up on the client side when I looked on my shared hosting I found that stores function to create a directory with no executable to world permission 700 and I wanted to be 755 or 777.

I tried to change the permissions of my shared hosting files but it works only once cuz when a new directory is created will create it with 700 permission

NIKUNJ PATEL
  • 2,034
  • 1
  • 7
  • 22

1 Answers1

0

You can create a helper function for common use inside whole application.

use Illuminate\Support\Facades\File;

function checkFolderExists($folder, $permission)
{
    if (!File::isDirectory(base_path('storage/' . $folder))) {
        File::makeDirectory(base_path('storage/' . $folder), $permission , true, true);
    }
    return 'public/' . $folder;
}

where

$folder = 'dropzone/upload/timestamp_date'

$permission = 0777 or 0775 or your_choice

And after check the store folder and permission your file store path with store image in that specific folder :

$filePath = checkFolderExists('dropzone/upload/timestamp_date', 0775 or 0777 or your_choice);
$fileStoredPath = $request->file('form_name_field')->store($filePath);
NIKUNJ PATEL
  • 2,034
  • 1
  • 7
  • 22