php文件上传入门级代码

这是一个新手写的上传文件,开始有点问题经过处理完全可以实现文件上传,支持任何类型.

  1. <form action="form.php教程" method="post" enctype="multipart/form-data">
  2. <input type="hidden" name="MAX_FILE_SIZE" value="100000000">
  3. <input type="file" name="spic"> <br>
  4. <input type="submit" name="sub" value="upload file"><br>
  5. <?php
  6. if(is_uploaded_file($_FILES['spic']['tmp_name'])){
  7. echo "<pre>";
  8. print_r($_FILES);
  9. move_uploaded_file($_FILES['spic']['tmp_name'],$_FILES['spic']['name']);
  10. echo "上传成功";
  11. echo "</pre>";
  12. }
  13. ?>
  14. </form>

运行过程,随便找个文件,显示如下:

  1. Array
  2. (
  3. [spic] => Array
  4. (
  5. [name] => IMG_0044.JPG
  6. [type] => image/jpeg
  7. [tmp_name] => F:TempphpF695.tmp
  8. [error] => 0
  9. [size] => 3737804
  10. )
  11. )