隐藏iframe无刷新上传文件,iframe刷新上传文件首先ajax不能上传文件,这误导了我有段时间,今晚睡不着就照着说明做了个无刷新上传文件
其实原理很简单
class upload
{
public $_file;
public function __construct( $name =null)
{
if(is_null($name) || !isset($_files[$name]))
$name = key($_files);
if(!isset($_files[$name]))
throw new exception(并没有文件上传);
$this->_file = $_files[$name];
if(!is_uploaded_file($this->_file['tmp_name']))
throw new exception(异常情况);
if($this->_file['error'] !== 0)
throw new exception(错误代码:.$this->_file['error']);
}
public function moveto( $new_dir)
{
$real_dir = $this->checkdir($new_dir);
return move_uploaded_file($this->_file['tmp_name'], $real_dir.'/'.$this->_file['name']);
}
private function checkdir($dir)
{
$real_dir = realpath($dir);
if($real_dir === false)
throw new exception(给定目录{$dir}不存在);
if(!is_writable($real_dir))
throw new exception(给定目录{$dir}不可写);
return $real_dir;
}
}
调用示例:
$inputname = 'uploadfile';
// 即 中的name值,不填也行
$upload = new upload($inputname);
$new_dir = /www; // 将文件移动到的路径
$upload->moveto($new_dir);
http://www.bkjia.com/phpjc/1105144.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/1105144.htmltecharticle隐藏iframe无刷新上传文件,iframe刷新上传文件 首先ajax不能上传文件,这误导了我有段时间,今晚睡不着就照着说明做了个无刷新上传文件...
