谈谈基于iframe、FormData、FileReader三种无刷新上传(3)

而如果设置为iframe的name值,即"upload"的话,就会在该iframe内打开,因为CSS设置为隐藏,因而不会有任何动静。若将display:none去掉,还会看到服务器的返回信息。 

--> upload.php <?php header("Content-type:text/html;charset=utf-"); class upload{ public $_file; public function __construct(){ if(!isset($_FILES['uploadfile'])){ $name=key($_FILES); } if(!isset($_FILES['uploadfile'])){ throw new Exception("并没有文件上传"); } $this->_file=$_FILES['uploadfile']; //$this->_file一维数组 var_dump($this->_file); //判断文件是否是通过 HTTP POST 上传的 //如果 filename 所给出的文件是通过 HTTP POST 上传的则返回 TRUE。这可以用来确保恶意的用户无法欺骗脚本去访问本不能访问的文件,例如 /etc/passwd。 if(!is_uploaded_file($this->_file['tmp_name'])) throw new Exception("异常情况"); if($this->_file['error'] !== ) throw new Exception("错误代码:".$this->_file['error']); } public function moveTo($new_dir){ $real_dir=$this->checkDir($new_dir).'https://www.jb51.net/'; $real_dir=str_replace("\\","https://www.jb51.net/",$real_dir); if(!move_uploaded_file($this->_file['tmp_name'],$real_dir.$this->_file['name'])){ exit('上传失败'); } echo "<script type='text/javascript'>alert('上传成功')</script>"; } public function checkDir($dir){ if(!file_exists($dir)){ mkdir($dir,,true); } return realpath($dir); } } $upload=new upload(); $new_dir="./a/b"; $upload->moveTo($new_dir);

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgzzxg.html