// 1、index.html <html> <body> <form action="upload_file.php" method="post" enctype="multipart/form-data"> <label for="myFile">Filename:</label> <input type="file" name="myFile" id="myFile" /> <br /> <input type="submit" name="submit" value="上传文件" /> </form> </body> </html> // 2、upload_file.php <?php if($_POST['submit'] != null && $_FILE['myFile']['error'] == 0){ /** There is a post submission and the upload file is successful. Here you can do file restrictions, such as storing files to the server, restricting file types, file sizes, etc. */ // store file if(move_uploaded_file($_FILES["file"]["tmp_name"], "/upload/" . $_FILES["file"]["name"]) ) { echo "Upload successful" } // Limit the file type, whether it is in jpg format if(($_FILES["file"]["type"] == "image/jpeg") { echo "Upload successful"; } // Limit file size (unit is Byte), is it less than 2M if($_FILES["file"]["size"] < 2097152){ echo "Upload successful"; } }
PHP receive storage upload file logic
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=324586093&siteId=291194637
Recommended
Ranking