我根据教材写的上传代码写的程序,在上传其他类型,比如xxx.txt;xxx.jpg等 类型文件没有出错,但是上传XXX.rar文件就出现以下错误Warning: move_uploaded_file(upload/XXX.rar) [function.move-uploaded-file]: failed to open stream: Invalid argument in F:\wamp\www\wenjian\dreamkiller\common.php on line 71Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'F:\wamp\tmp\phpB658.tmp' to 'upload/XXX.rar' in F:\wamp\www\wenjian\dreamkiller\common.php on line 71希望大家帮忙解决啊:上传的部分代码是:
<?php
//定义上传上来的文件存放的目录,注意是相对目录
define("UPLOAD_PATH","upload/");
//限制大小,6M
define("UPLOAD_MAX_SIZE",64*1024);//文件上传类
class CUpload
{
const UPLOAD_ERR_TOO_BIG =10;
const UPLOAD_ERR_CANT_MOVE = 11; private $error;//错误码
private $size;//文件大小
private $name;//文件名称
private $basename;//初始文件名
private $ext_name;//临时文件名
private $dest_dir;//保存上传文件的目标路径 //....................................
//功能:构造函数
//参数:$name ->表单中上传文件控件的名称,
//$dest_dir ->保存上传文件的相对路径
//....................................
public function __construct($Name,$dest_dir)
{
$this->error = $_FILES[$Name]['error'];
if($this->isOK())
{
$path_part = pathinfo($_FILES[$Name]['name']);//整个文件名包括,后缀
$this->size = $_FILES[$Name]['size'];//大小
$this->name = $path_part['basename'];//完整的文件名,如abc.txt
$this->ext_name = '.'.$path_parts['extension'];//获取扩展名.txt
$this->basename = basename($this->name,$this->ext_name);//获取文件名 abc,无后缀
$this->tmp_name = $_FILES[$Name]['tmp_name'];//$_FILES["file"]["tmp_name"];//临时文件名
if($this->size > UPLOAD_MAX_SIZE)
{
//文件太大啦
$this->error = CUpload::UPLOAD_ERR_TOO_BIG;
}
}
else
{
$this->size = 0;
$this->name = '';
$this->basename = '';
$this->ext_name = '';
$this->tmp_name = '';
}
$this->dest_dir = $dest_dir;
}
//..........................................
//上传,将临时文件移动到目标目录
//参数:无
//返回值:成功 = true,失败 = false
//..........................................
public function upload()
{
if(!$this->isOK())
return;
//新建文件名
$uploadfile = $this->dest_dir.$this->name;
//判断文件是否已经存在,如已存在则随机命名
if(file_exists($uploadfile))
{
$this->name = $this->basename.rand().$this->ext_name;
$uploadfile = $this->dest_dir.$this->name;
} //将文件重新命名并移动到目标路径
if(!move_uploaded_file($this->tmp_name,$uploadfile))////这里提示错误
{
$this->error = CUpload::UPLOAD_ERR_CANT_MOVE;
return false;
}
return true;
}
//判断上传是否成功
public function isOK()
{
return(($this->error === UPLOAD_ERR_OK)?true:false);
}

//取错误
public function getError()
{
switch($this->error)
{
case UPLOAD_ERR_OK : return '上传成功!';
case UPLOAD_ERR_INT_SIZE:
case UPLOAD_ERR_FORM_SIZE:
case UPLOAD_ERR_TOO_BIG : return '文件太大';
case UPLOAD_ERR_PARTIAL : return '文件未上传完整';
case UPLOAD_ERR_NO_FILE : return '未选择文件';
case UPLOAD_ERR_NO_TMP_DIR://没有临时目录
case UPLOAD_ERR_CANT_WRITE: return '内部错误';//无法写入文件
default:return '';
}
}
//取调用upload()方法后的相对文件名
public function getDestFile()
{
return $this->dest_dir.$this->name;
}
}
//数据库链接操作
function db_connect()
{
//调用mysqli的构造函数建立链接,同时选用数据库‘test’
$db = @new mysqli("localhost","root","","test"); //检查数据库链接
if(mysqli_connect_errno())
{
echo"数据库链接失败!<br>\n";
echo mysqli_connect_error();
exit;//退出程序,后面的语句将不再执行
}
return $db;
}
//下载资源函数
function download($filename)
{
//取不含路径的文件名
$fn = basename($filename);
//发送HTTP头
header("Cache-Control: cache");
header("Pragma: cache");
header("Content-type: application/octet-stream");
//指示文件大小
header("Content-Length: ".filesize($filename));
//指示文件名
header("Content-Disposition: attachment; filename=$fn");

//打开文件
$fp = fopen($filename,'rb');
//输出所有文件
fpassthru($fp);

?>