i need to copy an image and save in diferent name. how can i do this in laravel?
Please help me.
img/master.jpg -> copy -> paste with different name (user1)
----now------
img/master.jpg
img/user1.jpg
You can use laravel File
helper, here is the file 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");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With