<?phpclass Uploader_xhr
{
public function __construct(){}
public function save($path)
{
$input = fopen("php://input", "r");
$temp = tmpfile();
$size = stream_copy_to_stream($input, $temp);
fclose($input);
if ($size != $this->get_file_size()){
return false;
}
$target = fopen($path, "w");
fseek($temp, 0, SEEK_SET);
stream_copy_to_stream($temp, $target);
fclose($target);
return true;
}
public function get_file_name()
{
return $_GET['qqfile'];
}
public function get_file_size()
{
if(isset($_SERVER["CONTENT_LENGTH"]))
{
return (int)$_SERVER["CONTENT_LENGTH"];
}
else
{
throw new Exception('不支持获取文件大小.');
}
}
}