예제 #1
0
파일: Pet.php 프로젝트: sergeyusatyuk/HOLJ
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         $petImage = new PetImage();
         $files = UploadedFile::getInstances($petImage, 'source_url');
         foreach ($files as $file) {
             $explodedImage = explode('.', $file->name);
             $extension = end($explodedImage);
             $fileName = 'images/pets/' . time() . '_' . rand(10000, 99999) . '.' . $extension;
             $file->saveAs($fileName);
             $petImage = new PetImage();
             $petImage->source_url = $fileName;
             $petImage->pet_id = $this->id;
             $petImage->alt = '';
             if (!$petImage->save()) {
                 echo '<pre>';
                 var_dump($petImage->getErrors());
                 die;
             }
         }
         return true;
     }
     return false;
 }
예제 #2
0
 public function actionRemove($id)
 {
     /** @var PetImage $model */
     $model = PetImage::findOne(['id' => $id]);
     @unlink($model->source_url);
     $model->delete();
     return;
 }