Home  >  Article  >  Backend Development  >  A simple example of php file upload (for beginners)

A simple example of php file upload (for beginners)

WBOY
WBOYOriginal
2016-07-25 08:55:51745browse
  1. /**
  2. * php file upload
  3. * 2013-11-30
  4. */
  5. if($_POST[sub]){
  6. if(is_uploaded_file($_FILES[file][tmp_name])){//Determine whether to get it Temporary file and saved inside php. A return value of 1 is true.
  7. $file=$_FILES[file];
  8. print_r($file); // bbs.it-home.org
  9. $name=$file[name];
  10. $tmp=$file[tmp_name];
  11. $size= $file[size];
  12. $error=$file[error];
  13. $type=$file[type];
  14. }
  15. switch($type){
  16. case 'image/pjpeg' : $ok=1;
  17. break ;
  18. case 'image/jpeg' : $ok=1;
  19. break;
  20. case 'image/gif' : $ok=1;
  21. break;
  22. case 'image/png' : $ok=1;
  23. break;
  24. }
  25. if($error=='0'&& $ok==1){
  26. move_uploaded_file($tmp,'upfile/'.$name);
  27. echo "Upload successful";
  28. }else{
  29. echo "Upload failed ";
  30. }
  31. }
  32. ?>
Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn