[File Storage Help] Create Personalised Directory/Rename And Move Hi i have a user story where a user uploads there image, then a personalised directory gets created for this specific user. The users image gets renamed to "photo" and then moved into there personalised directory. How can i do this. Here is what i have so far
$usersDirectory = Storage::makeDirectory($user->id);
if($request->hasFile('user_image')
{
$userImage = $request->file('user_image');
}
Have a look at the "Moving Uploaded Files" section in the docs .
@ohffs
Im having a problem where it can't find the newly moved file but i can see it there in my IDE.
Create New Directory With User ID within App/Storage/Attachments as a subfolder
Move uploaded file to new directory and rename
Get the file using Storage::get
Store details such as name, size and path within an attachment resource
Storage::makeDirectory($user->id);
$attachment_storage = 'attachments';
$storage_path = storage_path() . '/app/' . $attachment_storage;
if ($request->hasFile('image')) {
$storage_path = $storage_path . '/' . $user->id . '/';
$image = $request->file('image');
$image->move($storage_path, 'photo' . '.' . $image->getClientOriginalExtension());
$mage = Storage::get($attachment_storage . '/'. $user->id . '/' . 'photo' . '.'. $image->getClientOriginalExtension());
$attachment = new Attachment();
$attachment->name = $image->getFilename();
$attachment->type = $image->getMimeType();
$attachment->path = $image->getPath();
$attachment->size = $image->getSize();
$attachment->save();
}
Please sign in or create an account to participate in this conversation.