/**
* uploasImg
* 私有方法 上传多张保存图片
* User:wangwei
* @param $name string 上传的图片文件名
* @return array [error_code,error_msg,path]
*/
private function uploadImg($name)
{
if (is_array($name)) {
$imgs = [];
//获取表单上传文件
$files = $this->request->file($name);
foreach ($files as $file) {
//移动到框架应用根目录/public/uploads/目录下
$info = $file->rule(\'uniqid\')->move(ROOT_PATH . \'public\' . DS . \'uploads\' . DS . \'ads\');
if ($info) {
// 成功上传后 获取上传信息
//输出 jpg
$imgs[] = \'/uploads/ads/\'.$info->getFilename();
} else {
echo $file->getError();
}
}
} else {
$imgs = \'\';
$files = $this->request->file($name);
$info = $files->rule(\'uniqid\')->move(ROOT_PATH . \'public\' . DS . \'uploads\' . DS . \'ads\');
if ($info) {
// 成功上传后 获取上传信息
//输出 jpg
$imgs[] = \'/uploads/ads/\'.$info->getFilename();
} else {
echo $files->getError();
}
}
return [\'error_code\' => 0, \'error_msg\' => \'\', \'name\' => $imgs];
}
相关文章: