我目前使用PHP到創建文件上傳系統。我從互聯網上獲得幫助併成功完成了這個項目。上傳後可以保留原文件名
但問題是,上傳後文件名會改變一些複雜的東西。例如:5987fff5b3dd83.21913884。
有沒有辦法保留上傳後的原始名稱。目前位置在Localhost但稍後我必須將其上傳到我的網站。
代碼的index.php
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form action="upload.php" method="POST" enctype="multipart/form-data">
<input type="file" name="file">
<button type="submit" name="submit">UPLOAD</button>
</form>
</body>
</html>
代碼upload.php的
<?php
if (isset($_POST['submit'])) {
$file = $_FILES['file'];
$fileName = $file['name'];
$fileTmpName = $file['tmp_name'];
$fileSize = $file['size'];
$fileError = $file['error'];
$fileType = $file['type'];
$fileExt = explode('.', $fileName);
$fileActualExt = strtolower(end($fileExt));
$allowed = array('jpg', 'jpeg', 'png', 'pdf');
if (in_array($fileActualExt, $allowed)) {
if ($fileError === 0) {
if ($fileSize < 1000000) {
$fileNameNew = uniqid('', true).".".$fileActualExt;
$fileDestination = 'uploads/'.$fileNameNew;
move_uploaded_file($fileTmpName, $fileDestination);
echo "OK";
header("Location: ab.html");
} else {
echo "Your file is too big!";
}
} else {
echo "There was an error uploading your file!";
}
} else {
echo "You cannot upload files of this type!";
}
}
請提出可能的方式來解決這個問題。
問候
惡劣邦薩爾
原來的文件名是在$ _FILES超級全局。請閱讀關於上傳文件主題的PHP手冊。 http://php.net/manual/en/features.file-upload.php – GordonM