$Fileobj = UploadedFile::getInstancesByName('file');
$leng = count($Fileobj);
for($i=0; $i<$leng; $i++) {
$FileUrl[] = \Helper::SaveUploadFile($Fileobj[$i], 'question');
}
public static function SaveUploadFile_avatar($file){
$time = time();
$targetPath = self::getImagePathInfo("avatar", true) .'/'. date('Ymd', $time);
if(!is_dir($targetPath)){
mkdir($targetPath, '0777', true);
}
$fileName = date('YmdHis', $time) . '_' . rand(10000, 99999) . '.' . strtolower($file->getExtensionName());
$filePath = $targetPath . '/' . $fileName;
if($file->saveAs($filePath)){
if(self::resizeImage($filePath, 147, 147, $targetPath)){
return '/'.date('Ymd', $time) . '/' . $fileName;
}else{
return false;
}
}
}
转载于:https://blog.51cto.com/jinliang/1637569