!DOCTYPE html>
html lang="en">
head>
meta charset="UTF-8">
title>Title/title>
/head>
body>
!--上傳文件 enctype="multipart/form-data"指的是編碼方式為上傳多種類型文件和數(shù)據(jù)流-->
form method="post" action="123.php" enctype="multipart/form-data">
input type="file" name="file">
input type="submit" value="上傳">
/form>
/body>
/html>
?php
/**
* Created by fcc
* User: Administrator
* Date: 2017/10/31
* Time: 10:33
*/
var_dump($_FILES);
//文件處理要實現(xiàn)的幾點
//1.是否有錯誤
//2.文件類型是否符合要求
//3.文件大小是否符合要求
//4.文件名是否重復(fù)
//$types = ['image/jpeg','image/png'];
if (!$_FILES['file']['error']){
if ($_FILES['file']['type'] == 'image/jpeg'){
if ($_FILES['file']['size']200000){
//文件傳到文件夾中,可以拼接時間戳,用戶名等防止文件名重復(fù)
$file_name = "./upload/2017-10-31/".$_FILES['file']['name'];
if (!file_exists($file_name)){
move_uploaded_file($_FILES['file']['tmp_name'],$file_name);
// $filename=iconv("UTF-8","",$file_name);
}else{
echo "文件名重復(fù)";
}
}else{
echo "文件過大";
}
}else{
echo "文件格式錯誤";
}
}
//實驗過程中出現(xiàn)因為圖片漢字命名報錯?。。?