Search code examples
phplaravellumen

Lumen get public directory


I want to store an image file with response like

http://localhost/storage/image/someimage.jpg

But when tried to use storage_path it returned

/home/../../../someimage.jpg

here's what i tried

   if ($request->hasFile('avatar_image')) {
      $image = $request->file('avatar_image');
      $name = time().'.'.$image->getClientOriginalExtension();
      $destinationPath = storage_path('images');
      $image->move($destinationPath, $name);

    $detail->update([
          'avatar_image' => env('APP_URL').$destinationPath.'/'.$name
       ]);
    }

Is there any way to get only the storage directory like /storage/image/... so i can concat it with my app_url


Solution

  • so what i did was symlink my storage/images with public folder then put it like

    if ($request->hasFile('avatar_image')) {
        $image = $request->file('avatar_image');
        $name = time().'.'.$image->getClientOriginalExtension();
        $destinationPath = storage_path('images');
        $image->move($destinationPath, $name);
        $file_path = env('APP_URL').'/public/images'.$name;
    
        $detail->update([
            'avatar_image' => $file_path
        ]);
      }
    

    it did works but dont know if its good enough