How can PHP be used to rename a file, such as changing "bild.jpg" to "bild2.jpg"?
To rename a file in PHP, you can use the `rename()` function. This function takes two parameters: the current file name and the new file name. In this case, to change "bild.jpg" to "bild2.jpg", you would use `rename('bild.jpg', 'bild2.jpg')`.
<?php
$old_name = 'bild.jpg';
$new_name = 'bild2.jpg';
if (rename($old_name, $new_name)) {
echo "File renamed successfully.";
} else {
echo "Error renaming file.";
}
?>
Keywords
Related Questions
- What are the necessary steps to integrate PayPal IPN and API for processing payments on a website?
- When implementing a commenting system on a website, what are the considerations for storing user comments in a database versus a text file, and how does this impact testing on XAMPP versus a live server?
- What is the significance of using isset() or empty() to check $_POST variables in PHP scripts?