ensure_writable_dir($path); //文件名 $name = "$md5.0x{$rawImageWidth}x{$rawImageHeight}{$extension}"; //加入图片文件没变化到,也就是存在,就不必重复上传了,不存在则上传 $ret = file_exists($path . $name) ? true : move_uploaded_file($item['tmp_name'], $path . $name); if ($ret === false) { $files[$index]['error'] = 8004; continue; } else { $files[$index]['path'] = $path . $name; //存图片路径 $files[$index]['success'] = true; //图片上传成功标志 $files[$index]['width'] = $rawImageWidth; //图片宽度 $files[$index]['height'] = $rawImageHeight; //图片高度 $success ++; //成功+1 } } $num = 0; if($files[$index]['type'] == 'image/xls'){ $file = $files[$index]['path']; $title = array( 'title' => array('col' => 'A', 'name' => '资料标题'), ); $excel = new \My\Excel(array('title'=>$title,'msg'=>L('common_not_data_tips'))); $data = $excel->Import($file); $num = $this->add_robots_info($data); } //将图片已json形式返回给js处理页面 ,这里大家可以改成自己的json返回处理代码 echo json_encode(array( 'total' => count($files), 'success' => $success, 'imgurl' => $path . $name, 'num' => $num, )); //echo $path . $name; } function ensure_writable_dir($dir) { if (!file_exists($dir)) { mkdir($dir, 0766, true); chmod($dir, 0766); chmod($dir, 0777); } else if (!is_writable($dir)) { chmod($dir, 0766); chmod($dir, 0777); if (!is_writable($dir)) { throw new FileSystemException("目录 $dir 不可写"); } } } public function add_robots_info($data){ $i = 0; foreach($data as $v){ $info['creat_at'] = date('Y-m-d H:i:s', time()); $info['title'] = $v['title']; M('robots')->add($info); $i++; } return $i; } } ?>