1、copy存储文件
public function uploadImage( CUploadedFile $cUploadFileObj,$sku='',$platform = 'mercadolibre'){
if (!in_array(strtolower($cUploadFileObj->extensionName), [ 'jpg', 'png', 'jpeg', 'gif' ])) {
$this->imageErrorMessage = '请上传后缀为jpg、png、jpeg、gif';
return false;
}
$imageName = $cUploadFileObj->name;
$tempName = $cUploadFileObj->tempName;
$imageUrl = self::SELF_UPLOAD_PATH.$platform.'/'.date('Ymd');
if ( !empty($sku) ) $imageUrl .= '/'.$sku;
$path = '/^[\w\-]{1,}\\.[a-zA-Z]{2,}$/'; #匹配不是 英文数字-_组成图片名称,重新命名图片名称
if(!preg_match($path,$imageName)){
$imageName = md5($imageName).'.'.pathinfo($imageName, PATHINFO_EXTENSION);
}
$imagePath = dirname($imageUrl.'/'.$imageName).'/'.$imageName;
$filePath = realpath($tempName);
if(!is_dir(dirname('.'.$imagePath))){
@mkdir(dirname('.'.$imagePath),0777, true);
}
if(!copy($filePath,'.'.$imagePath)){
$this->imageErrorMessage = 'copy执行失败。'.$filePath.'=>'.$imagePath;
return false;
}
$this->imagePathUrl = $imagePath;
return true;
}
Yii1.1上传组件