为了账号安全,请及时绑定邮箱和手机立即绑定

doAction5,php中dest未定义索引

doAction5,php

<?php

// print_r($_FILES);


require_once 'upload.func1.php';

require_once 'common.func.php';

$files=getFiles();

// print_r($_FILES);

foreach($files as $fileInfo){

$res=uploadFile($fileInfo);

echo $res['mes'],'<br/>';

$uploadFiles[]=$res['dest'];

}

$uploadFiles=array_values(array_filter($uploadFiles));

print_r($uploadFiles);




upload.func1.php

<?php


function getFiles(){

$i=0;

foreach($_FILES as $file){

if(is_string($file['name'])){

$files[$i]=$file;

$i++;

}elseif(is_array($file['name'])){

foreach($file['name'] as $key=>$val){

$files[$i]['name']=$file['name'][$key];

$files[$i]['type']=$file['type'][$key];

$files[$i]['tmp_name']=$file['tmp_name'][$key];

$files[$i]['error']=$file['error'][$key];

$files[$i]['size']=$file['size'][$key];

$i++;

}

}

}

return $files;

}






function uploadfile($fileInfo,$path='./uploads',$flag=true,$maxSize=1048576,$allowExt=array('jpeg','jpg','gif','png')){

// $flag=true;

// $allowExt=array('jpeg','jpg','gif','png');

// $maxSize=1048576;//1m

//判断错误号

if($fileInfo['error']===UPLOAD_ERR_OK){

    if($fileInfo['size']>$maxSize){

$res['mes']=$fileInfo['name'].'上传文件过大';

}

$ext=getExt($fileInfo['name']);

if(!in_array($ext,$allowExt)){

$res['mes']=$fileInfo['name'].'非法文件类型';

// 检测是否是真的图片类型

}

if($flag){

    if(!getimagesize($fileInfo['tmp_name'])){

    $res['mes']=$fileInfo['name'].'不是真实图片类型';

}

}

if(!is_uploaded_file($fileInfo['tmp_name'])){

$res['mes']=$fileInfo['name'].'文件不是通过HTTP POST方式上传上来的';

}

if (!empty($res)) return $res;

  

// $path='./uploads';

if(!file_exists($path)){

mkdir($phat,0777,true);

chmod($phat,0777);

 

}

$uniName=getUniName();

$destination=$path.'/'.$uniName.'.'.$ext;

   if(!move_uploaded_file($fileInfo['tmp_name'],$destination)){

           $res['mes']=$fileInfo['name'].'文件移动失败';

        }

$res['mes']=$fileInfo['name'].'上传成功';

$res['dest']=$destination;

return $res;   

}else{

//匹配错误信息

switch ($fileInfo ['error']) {

         case 1 :

            $mes = '上传文件超过了PHP配置文件中upload_max_filesize选项的值';

            break;

         case 2 :

            $mes = '超过了表单MAX_FILE_SIZE限制的大小';

            break;

         case 3 :

            $mes = '文件部分被上传';

            break;

         case 4 :

            $mes = '没有选择上传文件';

            break;

         case 6 :

            $mes = '没有找到临时目录';

            break;

         case 7 :

         case 8 :

            $mes = '系统错误';

            break;

      }

      echo ( $mes );

      return false;

   }

   $ext = pathinfo ( $fileInfo ['name'], PATHINFO_EXTENSION );

//     $allowExt = array (

//           'jpeg',

//           'jpg',

//           'png',

//           'gif' 

//     );

   if(!is_array($allowExt)){

      exit('系统错误');

   }

   // 检测上传文件的类型

   if (! in_array ( $ext, $allowExt )) {

      exit ( '非法文件类型' );

   }

   //$maxSize = 2097152; // 2M

                     // 检测上传文件大小是否符合规范

   if ($fileInfo ['size'] > $maxSize) {

      exit ( '上传文件过大' );

   }

   //检测图片是否为真实的图片类型

   //$flag=true;  

   if($flag){

      if(!getimagesize($fileInfo['tmp_name'])){

         exit('不是真实图片类型');

      }

   }

   // 检测文件是否是通过HTTP POST方式上传上来

   if (! is_uploaded_file ( $fileInfo ['tmp_name'] )) {

      exit ( '文件不是通过HTTP POST方式上传上来的' );

   }

   //$uploadPath = 'uploads';

   if (! file_exists ( $uploadPath )) {

      mkdir ( $uploadPath, 0777, true ); //创建一个upload文件夹,0777表示可读可写可执行

      chmod ( $uploadPath, 0777 );

   }

   $uniName = md5 ( uniqid ( microtime ( true ), true ) ) . '.' . $ext;

   $destination = $uploadPath . '/' . $uniName;

   if (! @move_uploaded_file ( $fileInfo ['tmp_name'], $destination )) {

      exit ( '文件移动失败' );

   }

   

   //echo '文件上传成功';

//     return array(

//        'newName'=>$destination,

//        'size'=>$fileInfo['size'],

//        'type'=>$fileInfo['type']

//     );

   return $destination;

}






正在回答

1 回答

执行 `$res=uploadFile($fileInfo);`这段代码返回的结果数组中,没有dest键,所以才会报这个错误。

要看看代码执行到哪一步返回了?如果在$res['dest']赋值之前返回,返回的结果中就没有dest键

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

doAction5,php中dest未定义索引

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信