一个简单的PHP上传文件的例子:
upload.html
<html> <body> <form action="upload.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>
upload.php
<?php move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; ?> <html> <head> <title>Upload complete</title> </head> <body> <h3>File upload succeeded...</h3> <ul> <li>Sent: <?php echo $_FILES['file']['name']; ?></li> <li>Size: <?php echo $_FILES['file']['size']; ?> bytes</li> <li>Type: <?php echo $_FILES['file']['type']; ?></li> </ul> </body> </html>
这里要注意两点: 当表单里面有上传文件的input时(即input='file'),表单form的enctype属性要设置为multipart/form-data HTML文件上传控件,我们一般使用<input type="file" >
演示:
上传的shell.php 会被保存到upload目录中
地址栏输入: http://192.168.1.135/upload/shell.php?command=phpinfo();
参考:
http://www.programgo.com/article/64921043351/
http://www.manongjc.com/article/983.html