我正在使用以下代碼上傳文件,一切正常,我只想上傳新名稱的文件,該名稱應(yīng)該是當(dāng)前上傳時(shí)間,實(shí)際上我想上傳名稱為上傳時(shí)間的文件<?php$statusMsg = '';// File upload path$targetDir = "../uploads/";$fileName = basename($_FILES["file"]["name"]);$targetFilePath = $targetDir . $fileName;$fileType = pathinfo($targetFilePath,PATHINFO_EXTENSION);if(isset($_POST["submit"]) && !empty($_FILES["file"]["name"])){ // Allow certain file formats $book_title=$_POST['book_title']; $allowTypes = array('jpg','png','jpeg'); if(in_array($fileType, $allowTypes)){ // Upload file to server if(move_uploaded_file($_FILES["file"]["tmp_name"], $targetFilePath)){ // Insert image file name into database $insert = mysqli_query($con,"INSERT into books (book_title,book_author,book_image,book_url) VALUES ('','','".$fileName."', '.')"); if($insert){ $statusMsg = "The file ".$fileName. " has been uploaded successfully."; }else{ $statusMsg = "File upload failed, please try again."; } }else{ $statusMsg = "Sorry, there was an error uploading your file."; } }else{ $statusMsg = 'Sorry, only JPG, JPEG, PNG, GIF, & PDF files are allowed to upload.'; }}else{ $statusMsg = 'Please select a file to upload.';}// Display status messageecho $statusMsg;?>
上傳PHP時(shí)如何重命名文件
動(dòng)漫人物
2023-03-11 15:48:08