$fileobj = UploadedFile::getInstanceByName(‘file‘);
\Helper::SaveUploadFile($fileobj, ‘openfireimg‘);
public static function SaveUploadFile($file, $folder) {
if(empty($file) || empty($folder)) {
return false;
}
$time = time();
$targetPath = self::getImagePathInfo($folder, true) .‘/‘. date(‘Ymd‘, $time);
if(!is_dir($targetPath)) {
mkdir($targetPath, ‘0777‘, true);
}
$fileName = date(‘YmdHis‘, $time) . ‘_‘ . rand(10000, 99999) . ‘.‘ . strtolower($file->extension);
$filePath = $targetPath . ‘/‘ . $fileName;
if($file->saveAs($filePath)) {
return ‘/‘.date(‘Ymd‘, $time) . ‘/‘ . $fileName;
} else {
return false;
}
}
时间: 2024-10-06 11:14:56