Lavravel cannot find the file to download

Asked

Viewed 29 times

0

I have a routine in the project where I attach documents but I can not in any way that Storage find the same.

This is my download method:

public function download($id)
{
    $anexo = PendenciaAnexo::where("id", "=", $id)->get()->first();        

    Storage::download(PathController::pathPendAnexos($anexo->pend_anexo_file_path));
}

This is another method I use to set a path for when I am in development and when I am with the project in production on the network:

public static function pathPendAnexos($file_path)
{
    if(ConfigController::modeOfDevelopment() == "production"){
        return '/storage/pend_anexos/'.$file_path.'';
    }else{
        return '/storage/public/pend_anexos/'.$file_path.'';
    }
}

Files in my project:

** absolute path within the project

C: laragon www Logisticsupportx public Storage public pend_attachments

** in the Storage folder:

C: laragon www Logisticsupportx Storage app public public pend_attachments

I’ve tried everything with several possible and absolute paths but nothing works, always this same mistake:

File not found at path: Storage/public/pend_attachments/PEND_80_ANEXO_4.pdf

But the files are there!!

  • Is there a folder called Storage inside the public folder? If you are in separate directories you can create a symbolic link to the public folder pointing to Storage

  • php Artisan Storage:link > vide doc https://laravel.com/docs/8.x/filesystem#the-public-disk

  • Actually this Storage is the symbolic link, but I do not understand why not find if the product registration I use something similar with the same path but with different folders!

  • This is the product list: Return '/Storage/public/products/'. $file_path.'';

1 answer

0

When you search for a file on Laravel, it will always leave the folder public, how are you keeping in storage, it is only necessary to return a folder first of all. Following example:

public static function pathPendAnexos($file_path)
{
    if(ConfigController::modeOfDevelopment() == "production"){
        return '../storage/pend_anexos/'.$file_path.'';
    }else{
        return '../storage/public/pend_anexos/'.$file_path.'';
    }
}
  • You have given this message now: Path is Outside of the defined root, path: [.. /Storage/public/pend_attachments/PEND_80_ANEXO_4.pdf]

  • When I put only one point gives the same message as before

  • @Ulissesgimenes you can attach your file config/filesystems.php in the question?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.