1
<body><form action= "chuli.php" method= "post" enctype= "Multipart/form-data" ><input type= "file" Name= " File "/><input type=" submit "value=" Upload "/></form></body>
chuli.php
<?PHP//All information about the uploaded file is saved in $_files["file"; inside the arrayEcho $_files["File"] ["Name"];//Take file nameEcho $_files["File"] ["type"];//Fetch file TypeEcho $_files["File"] ["Size"];//fetch File SizeEcho $_files["File"] ["Tmp_name"];//files are temporarily stored on the server pathEcho $_files["File"] ["Error"];//upload error message//File upload//1. Determine if there is an errorif($_files["File"] ["Error"]){ Echo"Upload Error";}Else{//2. Restrictions on adding conditionsif($_files["File"] ["Type"]== "Image/jpeg" &&$_files["File"] ["Size"]<1024000){//working with file names$str=Date("Ymdhisms", Time());//3. Create a storage path$url= "./img/".$str.$_files["File"] ["Name"];//converts the encoding format of the path to GB to prevent garbled file names$filename=Iconv("UTF-8", "gb2312",$url);if(file_exists($url)){Echo"The file already exists";}Else{//4. StorageMove_uploaded_file($_files["File"] ["Tmp_name"],$url));}}Else{Echo"The type of upload file does not meet the requirements";}}
PHP language-File Upload