Home > Backend Development > PHP Tutorial > iframe implements pseudo-AJAX file upload without refreshing

iframe implements pseudo-AJAX file upload without refreshing

WBOY
Release: 2016-07-25 08:48:57
Original
871 people have browsed it
  1. iframe无刷新上传文件/伪ajax上传
  2. 列表
复制代码
  1. $file = $_FILES['fileToUpload'];
  2. $fileType = array('image/gif','image/jpeg','image/pjpeg');
  3. $fileSize = 20000;
  4. // $extension = pathinfo($file['name'],PATHINFO_EXTENSION);
  5. // $name = date('YmdHis',time()).rand(1000,9999).'.'.$extension;
  6. if(!in_array($file['type'],$fileType)){
  7. echo "<script>window.parent.alert('类型错误');</script>";exit;
  8. }
  9. if($file['size']>$fileSize){
  10. echo "<script>window.parent.alert('文件太大');</script>";exit;
  11. }
  12. if ($file["error"] > 0){
  13. echo "<script>window.parent.alert('错误类型:".$file["error"]."');</script>";exit;
  14. }
  15. if (file_exists("upload/1" . $file["name"])){
  16. echo "<script>window.parent.alert('".$file["name"] . " already exists.');</script>";
  17. }else{
  18. if(move_uploaded_file($file["tmp_name"],"upload/" . $file["name"])){
  19. echo "<script>window.parent.show('". $file["name"] ."');</script>";
  20. }else{
  21. echo "<script>window.parent.alert('Upload failed!');</script>";
  22. }
  23. }
复制代码


source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template