这是一款简单的php 文件上传简单实例应用,适合入门者学习与理解文件上传的原理,PHP实例代码如下:
- <html>
- <head><title>php 文件上传简单实例应用</title></head>
- <body>
- <!-- 表单的enctype属性必须指定为multipart/form-data -->
- <form enctype="multipart/form-data" action="3.php" method="post">
- 上传此文件: <input name="myfile" type="file" />
- <input type="submit" value="提交上传" />
- </form>
-
- </body>
- </html>
-
-
- <?php
-
- $upload_path = $_server['document_root']."/upload/";
- $dest_file = $upload_path.basename($_files['myfile']['name']);
-
- if(move_uploaded_file($_files['myfile']['tmp_name'],$dest_file))
- {
- echo "文件已上传至服务器根目录的upload目录下";
- }
- else
- {
- echo "文件上传时发生了一个错误".$_files['myfile']['error'];
- }
- ?>
|