【发布时间】:2018-11-04 08:10:50
【问题描述】:
我想制作我的上传文件网站,所以当人们将文件上传到服务器时,我希望服务器增加文件的名称喜欢
- 1.png
- 2.png
- 3.png
那么,我怎样才能增加文件名呢?这是我的代码
<?php
$limitsize = 1000000;
$target_pics = "uploads/user/pics/" . basename($_FILES["fileToUpload"]["name"]);
$target_video = "uploads/user/video/" . basename($_FILES["fileToUpload"]["name"]);
$target_other = "uploads/user/other/" . basename($_FILES["fileToUpload"]["name"]);
$FileType = strtolower(pathinfo($target_video, PATHINFO_EXTENSION));
$uploadOk = 1;
// Check file exists
if (file_exists($target_pics) || file_exists($target_video) || file_exists($target_other)) {
echo "Sorry, file already exists. <br>";
$uploadOk = 0
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > $limitsize) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
} else {
if ($FileType == "jpg" || $FileType == "png" || $FileType == "jpeg" || $FileType == "gif" ) {
move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_pics);
echo "Upload Success.";
} else {
if ($FileType == "mp4" || $FileType == "avi") {
move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_video);
echo "Upload Success";
} else {
move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_other);
echo "Upload Success";
}
}
}
?>
【问题讨论】:
-
那么,问题出在哪里?目前得到了什么?