コード例 #1
0
ファイル: Log.php プロジェクト: danzabar/alice
 /**
  * Loads or creates the file
  *
  * @return void
  * @author Dan Cox
  */
 public function loadOrCreate()
 {
     if ($this->fs->exists(LOGS . $this->file)) {
         $this->config->load(LOGS . $this->file);
     } else {
         $this->config->create(LOGS . $this->file);
         $this->config->params()->created = array('date' => date('Y-m-d H:i:s'));
         $this->config->params()->log = array();
         $this->config->save();
     }
 }
コード例 #2
0
ファイル: row.php プロジェクト: vosaan/ankor.local
 /**
  * @see parent::save()
  */
 public function save()
 {
     if (!$this->OrderId) {
         return false;
     }
     return parent::save();
 }
コード例 #3
0
ファイル: type.php プロジェクト: vosaan/ankor.local
 /**
  * @see parent::save()
  */
 public function save()
 {
     if (!$this->Position) {
         $this->Position = intval(self::getLast($this, 'Position')) + 1;
     }
     return parent::save();
 }
コード例 #4
0
ファイル: document.php プロジェクト: vosaan/ankor.local
 /**
  * @see parent::save()
  */
 public function save()
 {
     if (!$this->Position) {
         $this->Position = intval(self::getLast($this, 'Position', array('ProductId = ' . $this->ProductId))) + 1;
     }
     return parent::save();
 }
コード例 #5
0
ファイル: announce.php プロジェクト: vosaan/ankor.local
 /**
  * @see parent::save()
  */
 public function save()
 {
     if (!$this->PostedAt) {
         $this->PostedAt = time();
     }
     return parent::save();
 }
コード例 #6
0
ファイル: Logs.php プロジェクト: alextalha/sg
 /**
  * Write log
  *
  * @return void
  */
 public function write()
 {
     if ($this->Model->name == 'Log') {
         return true;
     }
     $this->Log->id = null;
     $this->Log->save(array('Log' => array('authuser_id' => $this->Session->read('Usuario.id'), 'model' => $this->Model->name, 'action' => $this->_action, 'old_data' => $this->_oldData, 'new_data' => $this->_newData)));
 }
コード例 #7
0
ファイル: EntityTest.php プロジェクト: danzabar/alice
 /**
  * Test the save function
  *
  * @return void
  * @author Dan Cox
  */
 public function test_saveModel()
 {
     DI::addMock('database', $this->database);
     $this->database->shouldReceive('getEntity')->andReturn($this->database);
     $this->database->shouldReceive('persist');
     $this->database->shouldReceive('flush');
     $this->entity->save();
 }
コード例 #8
0
ファイル: CsvTest.php プロジェクト: kobabasu/rest-slim
 /**
  * 正常系 正しく保存されるか
  *
  * @covers Lib\Common\Csv::save()
  * @test testSaveNormal()
  */
 public function testSaveNormal()
 {
     $filename = 'test';
     $this->object->save($filename);
     $path = $this->object->getPath();
     $file = $path . $filename . '.csv';
     $res = file_exists($file);
     $this->assertTrue($res);
     unlink($file);
 }
コード例 #9
0
ファイル: reference.php プロジェクト: vosaan/ankor.local
 /**
  * @see parent::save()
  */
 public function save()
 {
     if (in_array($this->Layout, array(self::PAGE, self::PRODUCT)) && !$this->RefId) {
         return false;
     }
     if ($this->Layout == self::CATALOG && !$this->CategoryId && !$this->BrandId && !$this->TypeId && !$this->MaterialId) {
         return false;
     }
     return parent::save();
 }
コード例 #10
0
ファイル: file.php プロジェクト: helloandre/shortnsweet
 public function save()
 {
     if (!$this->store_file()) {
         throw new Error_Save("failed to move");
     }
     if (!parent::save()) {
         throw new Error_Save("failed to store");
     }
     // override long now so we can display it properly
     $this->long = SnS::make_url("file/" . $this->short . "-" . $this->long);
 }
コード例 #11
0
ファイル: url.php プロジェクト: helloandre/shortnsweet
 public function save()
 {
     $valid_gsb = Config::$gsb_key ? $this->check_gsb() : true;
     if (!$this->check_valid()) {
         throw new Error_Save("invalud url");
     }
     if (!$valid_gsb) {
         throw new Error_Save("unsafe url");
     }
     if (!parent::save()) {
         throw new Error_Save("could not save url");
     }
 }
コード例 #12
0
ファイル: Upload.php プロジェクト: jayxtt999/me
 private function saveBase64($type, $files)
 {
     $img = base64_decode($files);
     $fileCache['name'] = "scrawl" . time() . rand(1, 9999) . ".png";
     $fileCache['ext'] = "png";
     $saveName = $this->getSaveName($fileCache);
     if (!file_put_contents(ROOT_PATH . $this->cachePath . $saveName, $img) || !makeDir(ROOT_PATH . $this->cachePath)) {
         $this->error = "写入上传中转文件失败";
         return false;
     }
     /* 检测上传根目录 */
     if (!$this->uploader->checkRootPath($this->rootPath)) {
         $this->error = $this->uploader->getError();
         return false;
     }
     /* 检查上传目录 */
     //检验type,默认file
     $this->savePath = $this->savePath ? $this->savePath : array_key_exists($type, $this->type) ? $type . "/" : 'file/';
     if (!$this->uploader->checkSavePath($this->savePath)) {
         $this->error = $this->uploader->getError();
         return false;
     }
     /* 检测并创建子目录 */
     $subpath = $this->getSubPath($fileCache['name']);
     if (false === $subpath) {
         return;
     } else {
         $fileCache['savepath'] = $this->savePath . $subpath;
     }
     $fileCache['savename'] = $saveName;
     $fileCache['tmp_name'] = ROOT_PATH . $this->cachePath . $saveName;
     /* 获取文件hash */
     if ($this->hash) {
         $fileCache['md5'] = md5_file($fileCache['tmp_name']);
         $fileCache['sha1'] = sha1_file($fileCache['tmp_name']);
     }
     /* 保存文件 并记录保存成功的文件 */
     if ($this->uploader->save($fileCache, $this->replace, true)) {
         $this->error = $this->uploader->getError();
         $info[] = $fileCache;
     } else {
         $this->error = $this->uploader->getError();
     }
     unlink(ROOT_PATH . $this->cachePath . $saveName);
     if (isset($finfo)) {
         finfo_close($finfo);
     }
     return empty($info) ? false : $info;
 }
コード例 #13
0
 public function save()
 {
     if (empty($this->name)) {
         throw new \InvalidArgumentException('Missing required field "name"');
     }
     if (empty($this->idBoard)) {
         throw new \InvalidArgumentException('Missing required filed "idBoard" - id of the board that the list should be added to');
     }
     if (empty($this->pos)) {
         $this->pos = 'bottom';
     } else {
         if ($this->pos !== 'top' && $this->pos !== 'bototm' && $this->pos <= 0) {
             throw new \InvalidArgumentException("Invalid pos value {$this->pos}. Valid Values: A position. top, bottom, or a positive number");
         }
     }
     return parent::save();
 }
コード例 #14
0
 /**
  * Handle Add & Edit operations.
  * @return Array Success or Failure response.
  */
 protected function action_add_edit()
 {
     if (isset($_REQUEST['_wpnonce'])) {
         $nonce = sanitize_text_field(wp_unslash($_REQUEST['_wpnonce']));
     }
     if (!wp_verify_nonce($nonce, 'wpgmp-nonce')) {
         die('Cheating...');
     }
     $response = array();
     // Ignore changes in these class variables while setting up class object for insertion/updation.
     $properties_to_ignore = array('validations', 'table', 'unique');
     foreach ($properties_to_ignore as $classproperty) {
         if (array_key_exists($classproperty, $this->entityObjProperties)) {
             unset($this->entityObjProperties[$classproperty]);
         }
     }
     foreach (@$this->entityObjProperties as $key => $val) {
         if (isset($_POST[$key]) and !is_array($_POST[$key])) {
             $post_key = sanitize_text_field(wp_unslash($_POST[$key]));
         } else {
             $post_key = array_map('esc_attr', (array) wp_unslash($_POST[$key]));
         }
         if (isset($post_key)) {
             @$this->entityObj->set_val($key, $post_key);
         }
     }
     if (isset($_POST['entityID'])) {
         // Setting value of Id field in case of edit.
         $this->entityObj->set_val($this->entity . '_id', intval(wp_unslash($_POST['entityID'])));
     }
     if ($this->entityObj->save() > 0) {
         $current_obj_name = ucfirst($this->entity);
         if (isset($_GET['doaction']) and 'edit' == $_GET['doaction']) {
             $response['success'] = __($current_obj_name . ' updated successfully.', WPGMP_TEXT_DOMAIN);
         } else {
             $response['success'] = __($current_obj_name . ' added successfully. You can manage your ' . $current_obj_name . 's <a href="' . admin_url('admin.php?page=wpgmp_manage_' . $this->entity) . '">here</a>.', WPGMP_TEXT_DOMAIN);
         }
         $_POST = array();
     }
     return $response;
 }
 /**
  * blogBlogContentAfterSave
  * 
  * @param CakeEvent $event
  */
 public function blogBlogContentAfterSave(CakeEvent $event)
 {
     $Model = $event->subject();
     $created = $event->data[0];
     if ($created) {
         $contentId = $Model->getLastInsertId();
     } else {
         $contentId = $Model->data[$Model->alias]['id'];
     }
     $saveData = $this->_generateContentSaveData($Model, $contentId);
     if (isset($saveData['PetitBlogCustomFieldConfig']['id'])) {
         // ブログ設定編集保存時に設定情報を保存する
         $this->PetitBlogCustomFieldConfigModel->set($saveData);
     } else {
         // ブログ設定追加時に設定情報を保存する
         $this->PetitBlogCustomFieldConfigModel->create($saveData);
     }
     if (!$this->PetitBlogCustomFieldConfigModel->save()) {
         $this->log(sprintf('ID:%s のプチ・カスタムフィールド設定の保存に失敗しました。', $Model->data['PetitBlogCustomFieldConfig']['id']));
     }
 }
コード例 #16
0
ファイル: ModuleCache.php プロジェクト: danzabar/alice
 /**
  * Removes a cache modules information
  *
  * @return void
  * @author Dan Cox
  */
 public function remove($key)
 {
     unset($this->cache->params()->{$key});
     $this->cache->save();
 }
コード例 #17
0
ファイル: image.php プロジェクト: vosaan/ankor.local
 /**
  * @see parent::save()
  */
 public function save()
 {
     $this->UpdatedAt = time();
     return parent::save();
 }
コード例 #18
0
ファイル: order.php プロジェクト: vosaan/ankor.local
 /**
  * @see parent::save()
  */
 public function save()
 {
     if (!$this->PostedAt) {
         $this->PostedAt = time();
     }
     if (parent::save()) {
         if ($this->rowsChanged) {
             foreach ($this->getRows() as $Row) {
                 $Row->OrderId = $this->Id;
                 $Row->save();
             }
         }
         return true;
     }
     return false;
 }
コード例 #19
0
ファイル: proud.php プロジェクト: vosaan/ankor.local
 /**
  * @see parent::save()
  */
 public function save()
 {
     if (parent::save()) {
         if (is_array($this->Units)) {
             $pos = 1;
             foreach ($this->Units as $item) {
                 $Unit = new Proud_Unit();
                 if ($item['Id']) {
                     $Unit = $Unit->findItem(array('Id = ' . $item['Id'], 'ProudId = ' . $this->Id));
                 }
                 if ($item['Name']) {
                     // save
                     $Unit->set($item);
                     $Unit->ProudId = $this->Id;
                     $Unit->Position = $pos++;
                     $Unit->save();
                 } else {
                     if ($Unit->Id) {
                         // delete
                         $Unit->drop();
                     }
                 }
             }
         }
         if (is_array($this->UnitsDelete)) {
             foreach ($this->UnitsDelete as $id) {
                 $Unit = new Proud_Unit();
                 $Unit = $Unit->findItem(array('Id = ' . $id, 'ProudId = ' . $this->Id));
                 $Unit->drop();
             }
         }
         if (is_array($this->Models)) {
             $pos = 1;
             foreach ($this->Models as $item) {
                 $Model = new Proud_Model();
                 if ($item['Id']) {
                     $Model = $Model->findItem(array('Id = ' . $item['Id'], 'ProudId = ' . $this->Id));
                 }
                 if ($item['Name']) {
                     // save
                     $Model->set($item);
                     $Model->ProudId = $this->Id;
                     $Model->Position = $pos++;
                     $Model->save();
                 } else {
                     if ($Model->Id) {
                         // delete
                         $Model->drop();
                     }
                 }
             }
         }
         if (is_array($this->ModelsDelete)) {
             foreach ($this->ModelsDelete as $id) {
                 $Model = new Proud_Model();
                 $Model = $Model->findItem(array('Id = ' . $id, 'ProudId = ' . $this->Id));
                 $Model->drop();
             }
         }
         return true;
     }
     return false;
 }
コード例 #20
0
ファイル: merge.php プロジェクト: vuthaiphat/CakePHP-Assets
 /**
  * Merge two models into one, by effectivly joining them. By default target fields and associations will be used,
  * but sources will be used where there the target isnt available or both where that is possible. You can override
  * this on a field and association(alias) basis should you need to.
  * 
  * NB when merging with associations that are binded realtime, reset (2nd parameter of Model::bindModel) needs to be false
  *
  * @example $this->Post->merge(1,2,array('title'=>'source','author_id'=>'input'),array('Comment'=>'source'),$data);
  * @param Object $Model
  * @param int $target_id
  * @param int $source_id
  * @param array $field_options
  * @param array $data
  * @return boolean success
  */
 function merge(&$Model, $target_id, $source_id, $field_options = array(), $assoc_options = array(), $data = array())
 {
     $fields = am($this->settings[$Model->alias], $field_options);
     $target = $Model->find('first', array('conditions' => array($Model->primaryKey => $target_id), 'recursive' => -1));
     $source = $Model->find('first', array('conditions' => array($Model->primaryKey => $source_id), 'recursive' => -1));
     $new_values = array();
     foreach ($fields as $key => $value) {
         switch ($value) {
             case 'source':
                 $new_values[$key] = $source[$Model->alias][$key];
                 break;
             case 'target_source':
                 $new_values[$key] = $target[$Model->alias][$key] . "\n " . $source[$Model->alias][$key];
                 break;
             case 'source_target':
                 $new_values[$key] = $source[$Model->alias][$key] . "\n " . $target[$Model->alias][$key];
                 break;
             case 'input':
                 $new_values[$key] = $data[$Model->alias][$key];
                 break;
             case 'target':
             case FALSE:
             default:
                 break;
         }
     }
     // belongsTo is taken care of above with fields
     // hasOne - default is target, options are target, source, neither
     foreach ($Model->hasOne as $assoc_model => $assoc_setup) {
         $className = $assoc_setup['className'];
         $foreignKey = $assoc_setup['foreignKey'];
         $dependent = $assoc_setup['dependent'];
         if (!isset($assoc_options[$assoc_model]) && !isset($assoc_options['hasOne'][$assoc_model])) {
             $use = 'target';
             // default behaviour
         } else {
             if (isset($assoc_options['hasOne']) && isset($assoc_options['hasOne'][$assoc_model])) {
                 $use = $assoc_options['hasOne'][$assoc_model];
             } else {
                 $use = $assoc_options[$assoc_model];
             }
         }
         switch ($use) {
             case 'neither':
                 // delete or reset both
                 if ($dependent) {
                     $Model->{$assoc_model}->deleteAll(array($foreignKey => array($source_id, $target_id)));
                 } else {
                     $Model->{$assoc_model}->updateAll(array($foreignKey => NULL), array($foreignKey => array($source_id, $target_id)));
                 }
                 break;
             case 'target':
                 // keep old target, delete or reset assoc for source
                 if ($dependent) {
                     $Model->{$assoc_model}->deleteAll(array($foreignKey => array($source_id)));
                 } else {
                     $Model->{$assoc_model}->updateAll(array($foreignKey => NULL), array($foreignKey => $source_id));
                 }
                 break;
             case 'source':
                 // delete or reset target, use source
                 if ($dependent) {
                     $Model->{$assoc_model}->deleteAll(array($foreignKey => array($target_id)));
                 } else {
                     $Model->{$assoc_model}->updateAll(array($foreignKey => NULL), array($foreignKey => $target_id));
                 }
                 $Model->{$assoc_model}->updateAll(array($foreignKey => $target_id), array($foreignKey => $source_id));
                 break;
             default:
                 return FALSE;
         }
     }
     // hasMany - default is both, options are : target,source,neither,both
     foreach ($Model->hasMany as $assoc_model => $assoc_setup) {
         $className = $assoc_setup['className'];
         $foreignKey = $assoc_setup['foreignKey'];
         $dependent = $assoc_setup['dependent'];
         if (!isset($assoc_options[$assoc_model]) && !isset($assoc_options['hasMany'][$assoc_model])) {
             $use = 'both';
             // default behaviour
         } else {
             if (isset($assoc_options['hasMany']) && isset($assoc_options['hasMany'][$assoc_model])) {
                 $use = $assoc_options['hasMany'][$assoc_model];
             } else {
                 $use = $assoc_options[$assoc_model];
             }
         }
         switch ($use) {
             case 'both':
                 $Model->{$assoc_model}->updateAll(array($foreignKey => $target_id), array($foreignKey => $source_id));
                 break;
             case 'neither':
                 if ($dependent) {
                     $Model->{$assoc_model}->deleteAll(array($foreignKey => array($source_id, $target_id)));
                 } else {
                     $Model->{$assoc_model}->updateAll(array($foreignKey => NULL), array($foreignKey => array($source_id, $target_id)));
                 }
                 break;
             case 'target':
                 if ($dependent) {
                     $Model->{$assoc_model}->deleteAll(array($foreignKey => array($source_id)));
                 } else {
                     $Model->{$assoc_model}->updateAll(array($foreignKey => NULL), array($foreignKey => $source_id));
                 }
                 break;
             case 'source':
                 if ($dependent) {
                     $Model->{$assoc_model}->deleteAll(array($foreignKey => array($target_id)));
                 } else {
                     $Model->{$assoc_model}->updateAll(array($foreignKey => NULL), array($foreignKey => $target_id));
                 }
                 $Model->{$assoc_model}->updateAll(array($foreignKey => $target_id), array($foreignKey => $source_id));
                 break;
             default:
                 return FALSE;
         }
     }
     // HABTM - default is both, options are : target,source,neither,both
     foreach ($Model->hasAndBelongsToMany as $assoc_model => $assoc_setup) {
         $className = $assoc_setup['className'];
         $foreignKey = $assoc_setup['foreignKey'];
         //$assocForeignKey = $assoc_setup['associationForeignKey'];
         $joinModel = $Model->name . 's' . $className;
         if (!isset($assoc_options[$assoc_model]) && !isset($assoc_options['habtm'][$assoc_model])) {
             $use = 'both';
             // default behaviour
         } else {
             if (isset($assoc_options['habtm']) && isset($assoc_options['habtm'][$assoc_model])) {
                 $use = $assoc_options['habtm'][$assoc_model];
             } else {
                 $use = $assoc_options[$assoc_model];
             }
         }
         switch ($use) {
             case 'both':
                 $Model->{$joinModel}->updateAll(array($foreignKey => $target_id), array($foreignKey => $source_id));
                 break;
             case 'neither':
                 $Model->{$joinModel}->deleteAll(array($foreignKey => array($source_id, $target_id)));
                 break;
             case 'target':
                 $Model->{$joinModel}->deleteAll(array($foreignKey => array($source_id)));
                 break;
             case 'source':
                 $Model->{$joinModel}->deleteAll(array($foreignKey => array($target_id)));
                 $Model->{$joinModel}->updateAll(array($foreignKey => $target_id), array($foreignKey => $source_id));
                 break;
             default:
                 return FALSE;
         }
     }
     $data = $target;
     $data[$Model->alias] = array_merge($data[$Model->alias], $new_values);
     if ($Model->save($data, false)) {
         $Model->delete($source_id, false);
     }
     return true;
 }
コード例 #21
0
ファイル: Ue.class.php プロジェクト: TedaLIEz/AUNET
      header("Content-Type: text/html; charset=utf-8");
      /* 修改catcherLocalDomain 配置项,以解决SAE环境下图片抓取的bug*/
      $domain = $this->UE->getDomainUrl($this->config['rootPath']);
      if ($domain) {
          $this->config['catcherLocalDomain'][] = $domain;
      }
      /* 获取执行动作action名称 */
      $action = I('get.action');
      /* 抽取当前操作配置 */
      $this->actionConfig = $this->autoConfig($action, $this->config);
      /* 请求动作类型 switch */
      switch ($action) {
          /* 配置检测 */
          case 'config':
              $result = $this->config;
              break;
              /* 上传图片 */
          /* 上传图片 */
          case 'uploadimage':
              /* 上传视频 */
          /* 上传视频 */
          case 'uploadvideo':
              /* 上传文件 */
          /* 上传文件 */
          case 'uploadfile':
              $result = $this->upload();
              break;
              /* 上传涂鸦 */
          /* 上传涂鸦 */
          case 'uploadscrawl':
              $result = $this->upBase64();
              break;
              /* 列出图片 */
          /* 列出图片 */
          case 'listimage':
              /* 列出文件 */
          /* 列出文件 */
          case 'listfile':
              $result = $this->lister();
              break;
              /* 抓取远程文件 */
          /* 抓取远程文件 */
          case 'catchimage':
              $result = $this->catcher();
              break;
          default:
              $result = array('state' => '请求地址出错');
              break;
      }
      /* 输出结果 */
      $this->ueReturn($result);
  }
  /**
 * 输出返回给UE前端的必要信息
 * @param array $result 返回结果数组
 */
  private function ueReturn($result)
  {
      /* 错误捕捉 */
      if (empty($result)) {
          $result = array('state' => $this->getError());
      }
      /* json处理 */
      $result = json_encode($result);
      /* callback实现 */
      if (isset($_GET["callback"])) {
          if (preg_match("/^[\\w_]+\$/", $_GET["callback"])) {
              echo htmlspecialchars($_GET["callback"]) . '(' . $result . ')';
          } else {
              echo json_encode(array('state' => 'callback参数不合法'));
          }
コード例 #22
0
ファイル: article.php プロジェクト: vosaan/ankor.local
 /**
  * @see parent::save()
  */
 public function save()
 {
     if (parent::save()) {
         if ($this->tags !== null) {
             $Ref = new Article_Tag();
             $Ref->dropList(array('ArticleId = ' . $this->Id));
             foreach (explode(',', $this->tags) as $tag) {
                 $tag = trim($tag);
                 if ($tag) {
                     $Tag = new Tag();
                     $Tag = $Tag->findItem(array('Name = ' . $tag));
                     if (!$Tag->Id) {
                         $Tag->Name = $tag;
                         $Tag->save();
                     }
                     $Ref = new Article_Tag();
                     $Ref->ArticleId = $this->Id;
                     $Ref->TagId = $Tag->Id;
                     $Ref->saveNew();
                 }
             }
         }
         return true;
     }
     return false;
 }
コード例 #23
0
ファイル: page.php プロジェクト: vosaan/ankor.local
 /**
  * The function caches children count for current Page.
  *
  * @access public
  * @return bool TRUE on success, FALSE on failure.
  */
 public function cacheChildren()
 {
     if (!$this->Id) {
         return false;
     }
     $this->Children = $this->findSize(array('ParentId = ' . $this->Id));
     return parent::save();
 }
コード例 #24
0
ファイル: test.php プロジェクト: amilaev/test
        return $this->_name;
    }
    /**
     * Вернёт статус объекта.
     *
     * @return int
     */
    public function getStatus()
    {
        return $this->_status;
    }
    /**
     * Вернёт id объекта.
     *
     * @return int
     */
    public function getId()
    {
        return $this->_id;
    }
}
try {
    $object = new Object(1, new PDO("mysql:host=localhost;dbname=test", 'root', 'root'));
    $object->status = 2;
    $object->save();
    var_dump($object->getName());
} catch (PDOException $e) {
    echo "PDO error: " . $e->getMessage();
} catch (ObjectException $e) {
    echo $e->getMessage();
}
コード例 #25
0
 /**
  * Saves an image.
  *
  * @param string $output Output filename.
  * @param array $options Imagine image saving options.
  * @return bool
  */
 public function save($output, array $options = [])
 {
     $this->_image->save($output, $options);
     $this->_image = null;
     return true;
 }
コード例 #26
0
ファイル: Upload.class.php プロジェクト: 8yong8/vshop
    /**
     * 上传文件
     * @param 文件信息数组 $files ,通常是 $_FILES数组
     */
    public function upload($files='') {
        if('' === $files){
            $files  =   $_FILES;
        }
        if(empty($files)){
            $this->error = '没有上传的文件!';
            return false;
        }

        /* 检测上传根目录 */
        if(!$this->uploader->checkRootPath($this->rootPath)){
            $this->error = $this->uploader->getError();
            return false;
        }

        /* 检查上传目录 */
        if(!$this->uploader->checkSavePath($this->savePath)){
            $this->error = $this->uploader->getError();
            return false;
        }

        /* 逐个检测并上传文件 */
        $info    =  array();
        if(function_exists('finfo_open')){
            $finfo   =  finfo_open ( FILEINFO_MIME_TYPE );
        }
        // 对上传文件数组信息处理
        $files   =  $this->dealFiles($files);
        foreach ($files as $key => $file) {
            $file['name']  = strip_tags($file['name']);
            if(!isset($file['key']))   $file['key']    =   $key;
            /* 通过扩展获取文件类型,可解决FLASH上传$FILES数组返回文件类型错误的问题 */
            if(isset($finfo)){
                $file['type']   =   finfo_file ( $finfo ,  $file['tmp_name'] );
            }

            /* 获取上传文件后缀,允许上传无后缀文件 */
            $file['ext']    =   pathinfo($file['name'], PATHINFO_EXTENSION);

            /* 文件上传检测 */
            if (!$this->check($file)){
                continue;
            }

            /* 获取文件hash */
            if($this->hash){
                $file['md5']  = md5_file($file['tmp_name']);
                $file['sha1'] = sha1_file($file['tmp_name']);
            }

            /* 调用回调函数检测文件是否存在 */
            $data = call_user_func($this->callback, $file);
            if( $this->callback && $data ){
                if ( file_exists('.'.$data['path'])  ) {
                    $info[$key] = $data;
                    continue;
                }elseif($this->removeTrash){
                    call_user_func($this->removeTrash,$data);//删除垃圾据
                }
            }

            /* 生成保存文件名 */
            $savename = $this->getSaveName($file);
            if(false == $savename){
                continue;
            } else {
                $file['savename'] = $savename;
            }

            /* 检测并创建子目录 */
            $subpath = $this->getSubPath($file['name']);
            if(false === $subpath){
                continue;
            } else {
                $file['savepath'] = $this->savePath . $subpath;
            }

            /* 对图像文件进行严格检测 */
            $ext = strtolower($file['ext']);
            if(in_array($ext, array('gif','jpg','jpeg','bmp','png','swf'))) {
                $imginfo = getimagesize($file['tmp_name']);
                if(empty($imginfo) || ($ext == 'gif' && empty($imginfo['bits']))){
                    $this->error = '非法图像文件!';
                    continue;
                }
            }

            /* 保存文件 并记录保存成功的文件 */
			//缩略图
			if($this->thumb){
				mk_dir($this->rootPath);
				/*
				move_uploaded_file($file['tmp_name'],$this->rootPath.$savename);
				$file['tmp_name'] = $this->rootPath.$savename;
				*/
				//有缩略图先生成缩略图
				$basename = basename($file['savename']);
				if(move_uploaded_file($file['tmp_name'],$basename)){
					$image = getimagesize($basename);
					if (false !== $image) {
						//是图像文件生成缩略图
						$thumbWidth = explode(',', $this->thumbMaxWidth ? $this->thumbMaxWidth : C('thumbMaxWidth'));
						$thumbHeight = explode(',', $this->thumbMaxHeight ? $this->thumbMaxHeight : C('thumbMaxHeight'));
                        //原图压缩
                        if($this->thumbPrefix=='Original'){
                            $thumbPrefix[] = '';
                        }else{
						    $thumbPrefix = explode(',', $this->thumbPrefix ? $this->thumbPrefix : C('thumbPrefix'));                        
                        }
						$thumbSuffix = explode(',', $this->thumbSuffix);
						$thumbFile = explode(',', $this->thumbFile);
						// 生成图像缩略图
						$realFilename = $this->autoSub ? basename($file['savename']) : $file['savename'];
						$file_name = substr($realFilename, 0, strrpos($realFilename, '.'));
						$ext = substr($realFilename,strrpos($realFilename, '.'));//后缀
						for ($i = 0, $len = count($thumbWidth); $i < $len; $i++) {
							//[缩略图名 = 缩略图前缀 + 文件名 + 缩略图后缀名 + 文件后缀]
							$thumbname = $thumbPrefix[$i] . $file_name . $thumbSuffix[$i] . $ext;
							//生成缩略图
							$Image = new \Think\Image(1,$realFilename);
							$Image->thumb($thumbWidth[$i],$thumbHeight[$i]);
							//dump(basename($thumbname));
							$thumb = $Image->save(basename($thumbname));
							//原图改变为上一张缩略图
							$realFilename = $thumbname;
							//组装数组
							$thumbs[] = basename($thumbname);
						}
						if(!$this->thumbRemoveOrigin){
						  //原图也上传
						  $thumbs[] = basename($basename);
						}else{
						  unlink(basename($basename));
						}
						//移动上传图片
						foreach($thumbs as $thumbname){
							$file['tmp_name'] = $thumbname;
							$file['savename'] = $thumbname;
							if ($this->uploader->save($file,$this->replace)) {
								unset($file['error'], $file['tmp_name']);
							} else {
								$this->error = $this->uploader->getError();
							}
							//删除原件
							if(file_exists($thumbname)){
							  unlink(basename($thumbname));
							}						
						}
						$info[$key] = $file;
					}			    
				}else{
					$this->error = 'FTP上传失败';
					return false;
				}
			}else{
				if ($this->uploader->save($file,$this->replace)) {
					unset($file['error'], $file['tmp_name']);
					$info[$key] = $file;
				} else {
					$this->error = $this->uploader->getError();
				}			
			}

        }

        if(isset($finfo)){
            finfo_close($finfo);
        }
        return empty($info) ? false : $info;
    }
コード例 #27
0
ファイル: Method.php プロジェクト: xiaoguizhidao/extensiongsd
 /**
  * Authorize the subscription.
  *
  * @param Object $transaction
  * @throws Exception
  * @return Object
  */
 public function authorizeSubscription($transaction)
 {
     $adapter = $this->getHelper()->getAuthorizationAdapter(Customweb_Payment_Authorization_Recurring_IAdapter::AUTHORIZATION_METHOD_NAME);
     try {
         $adapter->process($transaction->getTransactionObject());
     } catch (Exception $e) {
         $transaction->save();
         throw $e;
     }
     $transaction->save();
     return $transaction;
 }
コード例 #28
0
ファイル: standard.php プロジェクト: vosaan/ankor.local
 /**
  * The function shows edit form and saves data on submit.
  * 
  * @access protected
  * @param object $Object The object.
  * @return string The HTML code.
  */
 protected function initForm(Object $Object, $method = 'edit')
 {
     $error = array();
     if (isset($_POST['submit'])) {
         $Object->setPost($_POST);
         //$fields = Locale::translate( Error::test( $Object ) );
         if (count($fields)) {
             $error[] = 'Неверно заполнены поля: ' . implode(', ', Locale::translate($fields));
         } else {
             if ($Object->save()) {
                 if (!empty($_FILES['file']['tmp_name'])) {
                     if (File::upload($Object, $_FILES['file'])) {
                         $Object->save();
                     } else {
                         if ($this->dropOnFailedUpload($Object)) {
                             $Object->drop();
                         }
                     }
                 }
                 if (!empty($_POST['detach'])) {
                     if (File::detach($Object)) {
                         $Object->save();
                     }
                 }
                 return $this->haltForm($Object, $method);
             } else {
                 $error[] = 'Ошибка базы данных: ' . $Object->getError();
             }
         }
     }
     $name = $this->getAliasName($method) ? $this->getAliasName($method) : $this->getModelName($method);
     $this->getView()->set($name, $Object);
     $this->getView()->set('Error', $error);
     return $this->getView()->render();
 }
コード例 #29
0
 /**
  * 上传文件
  * @param 文件信息数组 $files ,通常是 $_FILES数组
  */
 public function upload($files = '')
 {
     if ('' === $files) {
         $files = $_FILES;
     }
     if (empty($files)) {
         $this->error = '没有上传的文件!';
         return false;
     }
     /* 检测上传根目录 */
     if (!$this->uploader->checkRootPath($this->rootPath)) {
         $this->error = $this->uploader->getError();
         return false;
     }
     /* 检查上传目录 */
     if (!$this->uploader->checkSavePath($this->savePath)) {
         $this->error = $this->uploader->getError();
         return false;
     }
     /* 逐个检测并上传文件 */
     $info = array();
     if (function_exists('finfo_open')) {
         $finfo = finfo_open(FILEINFO_MIME_TYPE);
     }
     // 对上传文件数组信息处理
     $files = $this->dealFiles($files);
     foreach ($files as $key => $file) {
         $file['name'] = strip_tags($file['name']);
         if (!isset($file['key'])) {
             $file['key'] = $key;
         }
         /* 通过扩展获取文件类型,可解决FLASH上传$FILES数组返回文件类型错误的问题 */
         if (isset($finfo)) {
             $file['type'] = finfo_file($finfo, $file['tmp_name']);
         }
         /* 获取上传文件后缀,允许上传无后缀文件 */
         $file['ext'] = pathinfo($file['name'], PATHINFO_EXTENSION);
         /* 文件上传检测 */
         if (!$this->check($file)) {
             continue;
         }
         /* 获取文件hash */
         if ($this->hash) {
             $file['md5'] = md5_file($file['tmp_name']);
             $file['sha1'] = sha1_file($file['tmp_name']);
         }
         /* 调用回调函数检测文件是否存在 */
         $data = call_user_func($this->callback, $file);
         if ($this->callback && $data) {
             if (file_exists('.' . $data['path'])) {
                 $info[$key] = $data;
                 continue;
             } elseif ($this->removeTrash) {
                 call_user_func($this->removeTrash, $data);
                 //删除垃圾据
             }
         }
         /* 生成保存文件名 */
         $savename = $this->getSaveName($file);
         if (false == $savename) {
             continue;
         } else {
             $file['savename'] = $savename;
         }
         /* 检测并创建子目录 */
         $subpath = $this->getSubPath($file['name']);
         if (false === $subpath) {
             continue;
         } else {
             $file['savepath'] = $this->savePath . $subpath;
         }
         /* 对图像文件进行严格检测 */
         $ext = strtolower($file['ext']);
         if (in_array($ext, array('gif', 'jpg', 'jpeg', 'bmp', 'png', 'swf'))) {
             $imginfo = getimagesize($file['tmp_name']);
             if (empty($imginfo) || $ext == 'gif' && empty($imginfo['bits'])) {
                 $this->error = '非法图像文件!';
                 continue;
             }
         }
         /* 保存文件 并记录保存成功的文件 */
         if ($this->uploader->save($file, $this->replace)) {
             unset($file['error'], $file['tmp_name']);
             $info[$key] = $file;
         } else {
             $this->error = $this->uploader->getError();
         }
     }
     if (isset($finfo)) {
         finfo_close($finfo);
     }
     return empty($info) ? false : $info;
 }
コード例 #30
0
ファイル: Upload.class.php プロジェクト: jayfjso/pinsen
 /**
  * 上传文件
  * @param 文件信息数组 $files ,通常是 $_FILES数组
  */
 public function upload($files)
 {
     if (empty($files)) {
         $this->error = '没有上传的文件!';
         return false;
     }
     /* 检测上传根目录 */
     if (!$this->uploader->checkRootPath()) {
         $this->error = $this->uploader->getError();
         return false;
     }
     /* 检查上传目录 */
     if (!$this->uploader->checkSavePath($this->savePath)) {
         $this->error = $this->uploader->getError();
         return false;
     }
     /* 逐个检测并上传文件 */
     $info = array();
     foreach ($files as $key => $file) {
         /* 通过扩展获取文件类型,可解决FLASH上传$FILES数组返回文件类型错误的问题 */
         if (function_exists('mime_content_type')) {
             $file['type'] = mime_content_type($file['tmp_name']);
         }
         /* 获取上传文件后缀,允许上传无后缀文件 */
         $file['ext'] = pathinfo($file['name'], PATHINFO_EXTENSION);
         /* 文件上传检测 */
         if (!$this->check($file)) {
             continue;
         }
         /* 获取文件hash */
         if ($this->hash) {
             $file['md5'] = md5_file($file['tmp_name']);
             $file['sha1'] = sha1_file($file['tmp_name']);
         }
         /* 调用回调函数检测文件是否存在 */
         if ($this->callback && ($data = call_user_func($this->callback, $file))) {
             $info[$key] = $data;
             continue;
         }
         /* 生成保存文件名 */
         $savename = $this->getSaveName($file);
         if (false == $savename) {
             continue;
         } else {
             $file['savename'] = $savename;
         }
         /* 检测并创建子目录 */
         $subpath = $this->getSubPath($file['name']);
         if (false === $subpath) {
             continue;
         } else {
             $file['savepath'] = $this->savePath . $subpath;
         }
         /* 对图像文件进行严格检测 */
         $ext = strtolower($file['ext']);
         if (in_array($ext, array('gif', 'jpg', 'jpeg', 'bmp', 'png', 'swf'))) {
             $imginfo = getimagesize($file['tmp_name']);
             if (empty($imginfo) || $ext == 'gif' && empty($imginfo['bits'])) {
                 $this->error = '非法图像文件!';
                 continue;
             }
         }
         /* 保存文件 并记录保存成功的文件 */
         if ($this->uploader->save($file)) {
             unset($file['error'], $file['tmp_name']);
             $info[$key] = $file;
         } else {
             $this->error = $this->uploader->getError();
         }
     }
     return empty($info) ? false : $info;
 }