How can PHP be used to rename and save uploaded files to a specific location on the server?
To rename and save uploaded files to a specific location on the server using PHP, you can utilize the move_uploaded_file() function. This function moves an uploaded file to a new location and renames it if necessary. You can specify the destination directory and the new filename to achieve this.
$uploadedFile = $_FILES['file']['tmp_name'];
$destination = 'uploads/' . $_FILES['file']['name']; // Specify the destination directory and the new filename
move_uploaded_file($uploadedFile, $destination);
Related Questions
- What is the purpose of using curly braces in PHP when constructing SQL queries?
- How can PHP developers ensure that their code adheres to proper coding standards and practices recommended by the PHP community?
- In what scenarios would using functions like stristr(), strpos(), and substr be appropriate for manipulating strings in PHP?