How do I copy a image, and video from one location to another, and rename the file?

Joined
Aug 22, 2025
Messages
12
Reaction score
0
Hello.

May I please briefly ask:-

1. Once i've added a record into a database, and got the last record ID, I would like to copy a jpeg image from one folder to another, then rename it. May I ask if the snippet of code looks ok, as it doesn't copy, and doesn't rename.


Code:
$last_id = $conn->lastInsertId();
    //Create temporary profile image
    $entryfle = $last_id.".jpg";
    // Store the path of source file
    $source = '/central/system/graphics/noimage.jpg';
    // Store the path of destination file
    $destination = '/myaccount/profile/image/noimage.jpg';

    copy($source, $destination);
    rename("/myaccount/profile/image/noimage.jpg", "/myaccount/profile/image/". $entryfle);

2. Also, I'm unable to rename and move an uploaded video file. It will upload, but will not rename and move.

The line of code that doesn't work is:-

Code:
rename ("/video/add/upload/$filename", "/video/add/upload/$newfly");

$filename is the filename, chosen by the user, and it is renamed to $newfly. eg $newfly is made up vy $last_id.file-extenstion (1.mp4, 2.mp4 etc)

Thank You.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,347
Messages
2,571,447
Members
48,794
Latest member
Engareh

Latest Threads

Top