我是 yii 的新手,我正在使用 Asgaroth 的 Xupload 扩展。我在传输每个图像的模型时遇到问题。第一个循环没有上传我不知道它有什么问题。任何人都可以指出我的代码的确切错误?
这是我的模型的代码:
public function afterSave( ) {
$this->addImages( );
parent::afterSave( );
}
public function addImages(){
//If we have pending images
if(Yii::app()->user->hasState('images')){
$userId = Yii::app()->user->id;
$userImages = Yii::app( )->user->getState( 'images' );
//Resolve the final path for our images
$path = Yii::app()->getBasePath()."/../images/uploads/{$userId}/";
$thumbsPath = Yii::app()->getBasePath()."/../images/uploads/{$userId}/thumbs/";
$miniPath = Yii::app()->getBasePath()."/../images/uploads/{$userId}/thumbs/mini/";
//Create the folder and give permissions if it doesnt exists
if( !is_dir( $path ) ) {
mkdir( $path );
chmod( $path, 0777 );
}
if( !is_dir( $thumbsPath ) ) {
mkdir( $thumbsPath );
chmod( $thumbsPath, 0777 );
}
if( !is_dir( $miniPath ) ) {
mkdir( $miniPath );
chmod( $miniPath, 0777 );
}
foreach( $userImages as $image ) {
if( is_file( $image["path"] ) ) {
if( rename( $image["path"], $path.$this->id.'.'.$image["ext"] ) ) {
chmod( $path.$this->id.'.'.$image["ext"], 0777 );
rename($image['thumbnail_url'],$thumbsPath.$this->id.$image['ext']);
chmod( $thumbsPath.$this->id.$image['ext'], 0777 );
rename($image['mini_url'],$miniPath.$this->id.$image['ext']);
chmod( $miniPath.$this->id.$image['ext'], 0777 );
}
} else {
//You can also throw an execption here to rollback the transaction
Yii::log( $image["path"]." is not a file", CLogger::LEVEL_WARNING );
}
}
}
}