日期:2014-05-17 浏览次数:20710 次
<?php
ob_start();
$uploadDir = dirname(__FILE__).'/upload';
//自动创建目录
if(!file_exists($uploadDir)){
mkdir($uploadDir);
}
//如果PHP页面为UTF-8编码,请使用urldecode解码文件名称
//$fileName = urldecode($_FILES['postedFile']['name']);
//如果PHP页面为GB2312编码,则可直接读取文件名称
$fileName = basename($_FILES['FileName']['name']);//qq.exe
$tmpFilePath = $uploadDir . "/" . $fileName . ".tmp";
$tmpName = $_FILES['FileName']['tmp_name'];
$FileSize = $_POST['FileSize'];
$md5 = $_POST['md5'];
$complete = $_POST['complete'];
$RangePos = $_POST['RangePos'];
//移动文件
move_uploaded_file($tmpName,$tmpFilePath);
//upload/qq.exe
$savePath = $uploadDir . "/" . $fileName;
//文件不存在,创建
if(!file_exists($savePath))
{
$hfile = fopen($savePath,"wb");
ftruncate($hfile,$FileSize);
fclose($hfile);
}
//读取文件块数据
$hfileTemp = fopen($tmpFilePath,"rb");
$tempData = fread($hfileTemp,filesize($tmpFilePath));
fclose($hfileTemp);
//写入数据
$hfile = fopen($savePath,"r+b");
//定位到续传位置
fseek($hfile, $RangePos,SEEK_SET);
fwrite($hfile,$tempData);
fclose($hfile);
//删除临时文件
unlink($tmpFilePath);
//输出文件路径
//$_SERVER['HTTP_HOST'] localhost:81
//$_SERVER['REQUEST_URI'] /FCKEditor2.4.6.1/php/test.php
//$reqPath = str_replace("upload.php","",$_SERVER['REQUEST_URI']);
echo "upload/" . $fileName;
header('Content-Length: ' . ob_get_length());
?>
------解决方案--------------------