Php 上载具有不同名称的图像,但保留文件扩展名
当我用表单保存图像时,我更改了文件名。除了文件扩展名外,其他一切都很好。当我更改文件名时,扩展名丢失,文件保存时没有扩展名。请帮我解决我的问题,我想存储图像扩展 这是我更新图像名称的代码Php 上载具有不同名称的图像,但保留文件扩展名,php,laravel,Php,Laravel,当我用表单保存图像时,我更改了文件名。除了文件扩展名外,其他一切都很好。当我更改文件名时,扩展名丢失,文件保存时没有扩展名。请帮我解决我的问题,我想存储图像扩展 这是我更新图像名称的代码 $image = $request->file('image'); if ($image) { $imgPath = 'public/post-image/'; $imgName = uniqid('img_'); $store = $request->file('ima
$image = $request->file('image');
if ($image) {
$imgPath = 'public/post-image/';
$imgName = uniqid('img_');
$store = $request->file('image')->storeAs(
$imgPath, $imgName
);
$post->image = $imgName;
}
试试这个:
$image = $request->file('image');
if ($image) {
$imgPath = 'public/post-image/';
$imgName = uniqid('img_') . '.' . $image->extension();
$store = $image->storeAs($imgPath, $imgName);
$post->image = $imgName;
}
稍加修改,效果很好:)谢谢$图像->扩展()代码>