我正在使用以下代码上传文件,一切正常,我只想上传新名称的文件,该名称应该是当前上传时间,实际上我想上传名称为上传时间的文件
<?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 message
echo $statusMsg;
?>
米琪卡哇伊
慕尼黑8549860