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
- Are there any recommended resources or guidelines for PHP developers to follow in order to enhance the security of their applications when handling user input?
- How can PHP developers efficiently manage and manipulate multiple variables within an array structure to streamline code execution?
- What are the steps involved in generating and offering on-the-fly downloads in PHP without saving the file on the server or in a database?