I have a form which accepts a resume, and I would like the user to be able to upload files. I got this route to work, however, I want to replace the files uploaded by that user (I rename the file with their last name and the current time). My code is below:
$file = $request->file('cv');
$fileName = $user->id . "+" . date("Y-m-d H:i:s");
$destinationPath = config('app.CVDestinationPath') . "/" . $fileName . "." . $file->getClientOriginalExtension();
$uploaded = Storage::put($destinationPath, file_get_contents($file->getRealPath()));
if ($uploaded) { //update the database
dd("DONE");
}
So if a user has an id
of 2, and he uploads two files. I will have two files associated with that user. I want to replace any file with the id
of 2 if it exists. Can anyone provide any guidance?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire