Laravel - 复制图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29208204/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 11:11:23 来源:igfitidea点击:
Laravel - copy image
提问by Kombuwa
i need to copy an image and save in diferent name. how can i do this in laravel?
我需要复制一个图像并以不同的名称保存。我怎么能在 Laravel 中做到这一点?
Please help me.
请帮我。
img/master.jpg -> copy -> paste with different name (user1)
----now------
img/master.jpg
img/user1.jpg
回答by Kalhan.Toress
You can use laravel File
helper, here is the file System Doc.
您可以使用 laravelFile
助手,这是文件 System Doc。
$oldPath = 'images/1.jpg'; // publc/images/1.jpg
$newPath = 'images/2.jpg'; // publc/images/2.jpg
if (\File::copy($oldPath , $newPath)) {
dd("success");
}
if you need to rename it following would be helpful,
如果您需要重命名以下内容会有所帮助,
$oldPath = 'images/1.jpg'; // publc/images/1.jpg
$fileExtension = \File::extension($oldPath);
$newName = 'new file.'.$fileExtension;
$newPathWithName = 'images/'.$newName;
if (\File::copy($oldPath , $newPathWithName)) {
dd("success");
}