Home  >  Article  >  php教程  >  简易PHP登录上传程序

简易PHP登录上传程序

WBOY
WBOYOriginal
2016-06-06 20:09:35896browse

原因是我单独整了个子域名来托管文件提供下载之类的, 然后传文件要上FTP特别麻烦, 于是自己写了个简单的小程序. 实现的功能: 输入正确的用户名和密码后进入上传页面 无刷新上传 上传的文件保存到文件夹 包括三个文件: index.html check_usr.php upload_file.

原因是我单独整了个子域名来托管文件提供下载之类的, 然后传文件要上FTP特别麻烦, 于是自己写了个简单的小程序.

实现的功能:

  1. 输入正确的用户名和密码后进入上传页面
  2. 无刷新上传
  3. 上传的文件保存到文件夹

包括三个文件:

  1. index.html
  2. check_usr.php
  3. upload_file.php

index.html

Usr: 
Passwd: 

check_usr.php

 

Filename:
   
$(document).ready(function() {
  $('#editor-form').submit(function() {
    var options = {target: '#ooo',url: 'upload_file.php',type: 'post',success: function() {$('#filepath').val($('#ooo').text());}};
    $(this).ajaxSubmit(options);
    return false;
  });
});

upload_file.php

 0) {echo "Return Code: " . $_FILES["file"]["error"] ;
  } else {
    if (file_exists("files/" . $_FILES["file"]["name"])) {
     echo $_FILES["file"]["name"] . " already exists. ";
    } else {
      move_uploaded_file(     $_FILES["file"]["tmp_name"],      "files/"  . $_FILES["file"]["name"] );// save file	
      }
    }
  } else {echo "Invalid file";}  
?>
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