Home > Article > Backend Development > How to Customize File Names During File Uploads in PHP?
Customizing File Names during File Uploads
To upload and save files using PHP, you can utilize the provided code. However, if you wish to specify a custom name for the saved file, follow these steps:
$info = pathinfo($_FILES['userFile']['name']); $ext = $info['extension'];
$newname = "myFile.".$ext;
$target = 'images/'.$newname;
move_uploaded_file( $_FILES['userFile']['tmp_name'], $target);
By completing these adjustments to your code, you can upload and save files with user-defined names.
The above is the detailed content of How to Customize File Names During File Uploads in PHP?. For more information, please follow other related articles on the PHP Chinese website!