public function actionRemove($mid)
 {
     $photo = TemporaryFiles::model()->findByPk($mid);
     $photo->delete();
 }
 /**
  * Temporary method for clearing temp files linked with TempoaryFiles class
  * @todo remove!!!
  */
 public function actionCleartemp()
 {
     if (!YII_DEBUG) {
         exit;
     }
     $tmps = TemporaryFiles::model()->findAll('md5file IS NOT NULL');
     $path = realpath(Yii::app()->basePath . '/../upload/TemporaryFiles/');
     $result = true;
     if ($path !== FALSE) {
         //we will delete after successfully remove all data from database
         //though this is a transaction we couldn't know if the record where deleted or not
         //..not before commit
         $unlinks = array();
         $transaction = Yii::app()->db->beginTransaction();
         try {
             foreach ($tmps as $tmp) {
                 if (is_file($path . DIRECTORY_SEPARATOR . $tmp->filename)) {
                     $unlinks[] = $path . DIRECTORY_SEPARATOR . $tmp->filename;
                     $tmp->delete();
                 }
             }
             $transaction->commit();
             //$result = array_reduce($unlinks, function($res,$item){ return $res && @unlink($item);},$result);
         } catch (Exception $e) {
             $transaction->rollback();
         }
     }
     var_dump($result);
     exit;
 }
Esempio n. 3
0
 public function addFiles($post_id)
 {
     $folder = Yii::getPathOfAlias('webroot') . '/upload';
     foreach ($_POST['files'] as $files) {
         foreach ($files as $object_id => $type) {
             $this->isNewRecord = true;
             $this->id = 0;
             $this->posts_id = $post_id;
             $this->upload_date = time();
             if ($type == 'album') {
                 if ($photo = Photos::model()->findByPk($object_id)) {
                     if (file_exists($folder . '/photos/' . $photo['filename'])) {
                         $this->filename = $photo['filename'];
                         $this->type = 'photos';
                         $this->description = $photo['description'];
                         $this->save();
                     }
                 }
             } elseif ($type == 'uploaded') {
                 if ($temp = TemporaryFiles::model()->findByPk($object_id)) {
                     if (file_exists($folder . '/photos/' . $temp['filename'])) {
                         $this->filename = $temp['filename'];
                         $this->type = 'photos';
                         $this->description = $temp['description'];
                         $this->save();
                     }
                     $temp->delete();
                 }
             }
         }
     }
 }