php 图片上传move_uploaded_file 出错

出错:Warning:move_uploaded_file(upload/1074470835.jpg)[function.move-uploaded-file]:fai... 出错:
Warning: move_uploaded_file(upload/1074470835.jpg) [function.move-uploaded-file]: failed to
open stream: No such file or directory in C:\Program Files\Apache Software
Foundation\Apache2.2\htdocs\item\fileIt.php on line
15

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to
move 'D:\PHP\phpfileuploadtmp\phpC211.tmp' to 'upload/1074470835.jpg' in
C:\Program Files\Apache Software
Foundation\Apache2.2\htdocs\item\fileIt.php on line 15

原代码:
<html>
<body>
<form method="post" enctype="multipart/form-data" >
要上传的文件:
<input type="file" name="upFile" id="UpFile"/>
<input type="submit" value="上传"/>
</form>
<?php
if (array_key_exists("upFile", $_FILES) && $_FILES["upFile"]["error"] == UPLOAD_ERR_OK) {
$orgFilename = $_FILES["upFile"]["name"];
$ext = substr($orgFilename, strripos($orgFilename, "."));
$filename = mt_rand() . $ext;
move_uploaded_file($_FILES["upFile"]["tmp_name"], "upload/$filename");
echo $_FILES["upFile"]["tmp_name"];

echo $filename;
}

?>
<img src=
<?php echo "upload/" . $filename; ?>
>
</body>
</html>

到底错哪了0.0求高手
展开
 我来答
百度网友8b5ddc6
2013-08-05 · TA获得超过683个赞
知道小有建树答主
回答量:606
采纳率:0%
帮助的人:484万
展开全部
上传文件不存在。很可能是PHP临时文件夹不存在导致的。

<?php
/*
* 文件上传类
*/
class Uploads{

//上传文件
private $uploadFile;

//上传文件扩展名
private $ext = array('jpeg','jpg','gif','png');

//上传文件大小
private $size = 5000000;

//上传文件目录
private $uploadDir = './uploads/';

//是否自定义名称,默认FALSE
private $newName = '';

//上传文件是否可读,默认为TRUE
private $isRead = TRUE;

//上传文件是否可写,默认为TRUE
private $isWrite = TRUE;

//上传信息
private $info;

/*
* 文件上传类初始化
*/
public function __construct($newName='',$ext='',$size='',$dir='',$isRead=TRUE,$isWrite=TRUE){
$this->ext = empty($ext)?$this->ext:$ext;
$this->size = empty($size)?$this->size:$size;
$this->dir = empty($dir)?$this->uploadDir:$dir;
$this->newName = $newName;
$this->isRead = $isRead?TRUE:FALSE;
$this->isWrite = $isWrite?TRUE:FALSE;
}
/*
* 处理上传文件
*/
public function doUpload(){
$this->checkData();
$this->checkFile() or $this->error();
$this->checkExt() or $this->error();
$this->checkSize() or $this->error();
$this->checkError() or $this->error();
$this->checkDir() or $this->error();
$this->upload() or $this->error();
return $this->info['msg'];
}
/*
* 处理上传文件数据
*/
public function checkData(){
$num = 0;
$newArr = array();
foreach($_FILES as $v){
if(is_array($v['name'])){
$count = count($v['name']);
for($i=0; $i<$count; $i++){
foreach($v as $m=>$n){
$newArr[$num][$m] = $n[$i];
}
$num++;
}
}else{
$newArr[$num] = $v;
$num++;
}

}
$endArr = array();
foreach($newArr as $v){
if($v['name'] != ''){
$endArr[]=$v;
}
}
$this->uploadFile = $endArr;
}
/*
* 检测上传文件是否存在
*/
private function checkFile(){
if(empty($this->uploadFile)){
$this->info['error'] = '上传文件不得为空!!!';
return FALSE;
}
return TRUE;
}
/*
* 检测上传文件类型是否合法
*/

private function checkExt(){
if(!is_array($this->ext)){
$this->ext = explode(',', $this->ext);
}
foreach($this->uploadFile as $v){
$ext = strtolower(substr(strrchr(basename($v['name']),'.'),1));
if(!in_array($ext,$this->ext)){
$this->info['error'] = '上传文件类型非法,禁止上传!!!';
return FALSE;
}
}
return TRUE;
}

/*
* 检测上传文件大小
*/

private function checkSize(){
foreach($this->uploadFile as $v){
if($v['size']>$this->size){
$this->info['error'] = '上传文件体积过大,上传失败!!!';
return FALSE;
}
}
return TRUE;
}

/*
* 检测文件上传错误代码
*/
private function checkError(){
foreach($this->uploadFile as $v){
switch($v['error']){
case 0:
return TRUE;
break;
case 1:
$this->info['error'] = '上传的文件超过了 php.ini 中 upload_max_filesize 选项限制的值,上传失败!!!';
return FALSE;
break;
case 2:
$this->info['error'] = '上传文件的大小超过了 HTML 表单中 MAX_FILE_SIZE 选项指定的值,上传失败!!!';
return FALSE;
break;
case 3:
$this->info['error'] = '文件只有部分被上传!!!';
return FALSE;
break;
case 4:
$this->info['error'] = '没有文件上传!!!';
return FALSE;
break;
}
}
return TRUE;
}

/*
* 检测上传文件夹是否存在
*/

private function checkDir(){
if(!file_exists($this->uploadDir)){
mkdir($this->uploadDir,0777,true);
}
if(!is_writeable($this->uploadDir)){
$this->info['error'] = '上传目录没有写入权限,上传失败!!!';
return FALSE;
}
return TRUE;
}

/*
* 上传文件
*/

private function upload(){

date_default_timezone_set('PRC');

//检测文件是否自定义名称
$name = empty($this->newName)?date('Ymd_His'):$this->newName;
foreach($this->uploadFile as $k=>$v){
$upload_path = $this->uploadDir.$name.'_'.($k+1).strrchr(basename($v['name']),'.');
$upload_path = iconv('UTF-8','gbk',$upload_path);
if(is_uploaded_file($v['tmp_name'])){
if(move_uploaded_file($v['tmp_name'], $upload_path)){
if($this->isRead && $this->isWrite){
chmod($upload_path,0777);
}else if($this->isRead && !$this->isWrite){
chmod($upload_path,0444);
}else if(!$this->isRead && $this->isWrite){
chmod($upload_path,0222);
}else{
chmod($upload_path,0000);
}
$this->info['msg']=array('type'=>1,'success'=>'文件上传成功','path'=>iconv('gbk','UTF-8',$upload_path));
}else{
$this->info['error'] = '文件上传失败!!!';
return FALSE;
}
}
}
return TRUE;

}
/*
* 上传成功的方法
*/
public function success(){
echo $this->info['msg']['success'];
}

/*
* 上传文件错误方法
*/
public function error(){
echo $this->info['error'];
die;
}

这是我写的PHP类,你可以参考一下。有什么特殊需要的,你可以告诉我一下,完善一下上传类。
追问
我是问我那个代码错误的地方该怎么改正- -|||
jiangxibaiyi
2013-08-05 · 跟随风去旅行-伤心的歌
jiangxibaiyi
采纳数:3973 获赞数:14412

向TA提问 私信TA
展开全部
警告:move_uploaded_file(upload/1074470835.jpg)[function.move上传文件]:失败
打开流:没有这样的文件或目录在C:\ Program Files文件\ Apache软件
基金会APACHE2.2\\ htdocs中\项目\ fileIt.php上线
15

警告:move_uploaded_file()以[function.move上传文件]:无法
移动'D:\ PHP\ phpfileuploadtmp的\ phpC211.tmp'到'upload/1074470835.jpg
C:\ Program Files文件\ Apache软件
基金会APACHE2.2\\ htdocs中\项目\ fileIt.php第15行

上面是谷歌翻译后的错误提示
根据这个,你检查一下目录的存在以及目录的权限
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式