欢迎各位兄弟 发布技术文章
这里的技术是共享的
You should get the client original name. Here's an example.
In a next version of the package I'll make this easier.
Hi @alexglue
The way I currently handle it is this
// I can't find a rename method on UploadedFile class hence I used the move method to move on the
// same directory while providing a new filename, then I add the media to the object.
$file = $file->move('.', $file->getClientOriginalName());
$object->addMedia($file);
Hope it helps for the moment!
You could also rename the media after adding the file:
$media = $model->addMedia($request->file('file'));
$media->name = $file->getClientOriginalName();
$media->save();
Hi @freekmurze from my own attempt earlier doing that changes the name at the database row, but not the actual file name of the document.
@ziming that's true...
I'll add method for renaming the file soon...
New in version 2.2.3: when renaming file_name on a media object, the underlying file will be renamed as well.
$mediaObject->file_name = 'newFileName.jpg'
$mediaObject->save(); // This will also rename the file on the filesystem.
Fyi, working on allowing uploads to be passed directly to the addMedia
-function: c43e577
Still have to test it properly, ...
来自 https://github.com/spatie/laravel-medialibrary/issues/31
So i've got "phpCYQ7ed" (temporary php filename) instead of original uploaded file name.
Or maybe i should to store uploaded file separately before attach it to my model?
Don't u think it'll be better to integrate upload file moving-renaming in your package also?