samedi 30 septembre 2017

Laravel ajax deleting files fails

IN my vue js ajax post am storing file like

  $imagename = sha1(time()).".".$request->profile_pic->extension();
  $path = $request->profile_pic->storeAs('public/images/users',$imagename);
   $user = \Auth::user();
    //remove old file and retain new one
    if(\Storage::has($user->profile_pic)){
      \Storage::delete($user->profile_pic);
    }

   $user->picture = $path;
    $user->save();

THe above works and the image is saved in the storage/app/public/images/users which is okay

But the database field is saved as public/images/users so when accessing the value in the frontend its not found

After several tests i found out that in the database i need to save the file as

storage/images/users //note path is not starting with public

so i changed the

$user->picture="storage/images/users".$imagename;

But now after doing this the part that removes old file fails

if(\Storage::has($user->profile_pic)){
      \Storage::delete($user->profile_pic);
 }

How do i adjust the delete part to also work.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2wpUwDA
via IFTTT

Aucun commentaire:

Enregistrer un commentaire