简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM