How can PHP be used to save uploaded files with specific names instead of their original names?
When uploading files using PHP, by default, the uploaded files are saved with their original names. To save uploaded files with specific names instead of their original names, you can use the `move_uploaded_file()` function and specify the desired file name in the destination path.
<?php
if(isset($_FILES['file'])){
$file_name = "specific_name.jpg"; // Specify the desired file name here
$file_tmp = $_FILES['file']['tmp_name'];
$file_destination = "uploads/" . $file_name; // Specify the destination directory here
move_uploaded_file($file_tmp, $file_destination);
echo "File uploaded successfully!";
}
?>
Keywords
Related Questions
- Are there any specific PHP functions or libraries that simplify the process of deleting folders recursively?
- How does the choice of using gettext in PHP for language translations affect the scalability and performance of websites with multiple languages?
- In what situations should error handling be implemented when using fsockopen in PHP to check server availability?