html页面:
<html> <body> <form action="upload_file.php" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="Submit" /> </form> </body> </html>
php处理页面:
<?php var_dump($_FILES); if(($_FILES[‘file‘][‘type‘] == "image/gif" || $_FILES[‘file‘][‘type‘] == "image/jpeg" || $_FILES[‘file‘][‘type‘] == "image/pjpeg" || $_FILES[‘file‘][‘type‘] == "image/png") && ($_FILES[‘file‘][‘size‘] < 200000)) { if ($_FILES["file"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Stored in: " . $_FILES["file"]["tmp_name"]; /* 判断文件是否存在,不存在则烤白过来 * */ if(file_exists("upload/".$_FILES[‘file‘][‘name‘])) { print_r("file already exitst!"); } else { move_uploaded_file($_FILES[‘file‘][‘tmp_name‘], "upload/".$_FILES[‘file‘][‘name‘]); } } } else { print_r("不是图片文件类型或者文件超大!"); } ?>
时间: 2024-11-08 20:25:28