Kombuwa
Kombuwa

Reputation: 1651

Laravel - copy image

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

Upvotes: 4

Views: 11976

Answers (1)

Kalhan.Toress
Kalhan.Toress

Reputation: 21901

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");
}

Upvotes: 11

Related Questions