How to copy a file from one directory to another using PHP?
This should be pretty easy. You want to copy & rename images that already exist on the server while still retaining the original image.
Here’s the original image location:
images/
folder/
your_image_name.jpg
This is what I want:
images/
folder/
your_image_name.jpg
your_image_new_name.jpg
<?php
$file = ‘images/folder/your_image_name.jpg’;
$newfile = ‘Images/folder/your_image_new_name.jpg’;if (!copy($file, $newfile)) {
echo “failed to copy”;
}
Hope it will help you.