我是yii的新手,我正在使用Asgaroth的Xupload扩展程序..我的模型转移每个图像时出现问题..第一个循环没有被上传我不知道它有什么问题..can任何人都指出了我的代码的确切错误?
这是我的模型代码:
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 );
}
}
}
}