コード例 #1
0
ファイル: class_dm_attachment.php プロジェクト: holandacz/nb4
 /**
  * Any checks to run immediately before saving. If returning false, the save will not take place.
  *
  * @param	boolean	Do the query?
  *
  * @return	boolean	True on success; false if an error occurred
  */
 function pre_save($doquery = true)
 {
     if ($this->presave_called !== null) {
         return $this->presave_called;
     }
     // make sure we don't have the binary data set
     // if so move it to an information field
     // benefit of this is that when we "move" files from DB to FS,
     // the filedata/thumbnail fields are not blanked in the database
     // during the update.
     if ($file =& $this->fetch_field('filedata')) {
         $this->setr_info('filedata', $file);
         $this->do_unset('filedata');
     }
     if ($thumb =& $this->fetch_field('thumbnail')) {
         $this->setr_info('thumbnail', $thumb);
         $this->do_unset('thumbnail');
     }
     if (!empty($this->info['filedata'])) {
         $this->set('filehash', md5($this->info['filedata']));
         $this->set('filesize', strlen($this->info['filedata']));
     } else {
         if (!empty($this->info['filedata_location']) and file_exists($this->info['filedata_location'])) {
             $this->set('filehash', md5_file($this->info['filedata_location']));
             $this->set('filesize', filesize($this->info['filedata_location']));
         }
     }
     if (!empty($this->info['thumbnail'])) {
         $this->set('thumbnail_filesize', strlen($this->info['thumbnail']));
     }
     if (!empty($this->info['filedata']) or !empty($this->info['thumbnail']) or !empty($this->info['filedata_location'])) {
         $path = $this->verify_attachment_path($this->fetch_field('userid'));
         if (!$path) {
             $this->error('attachpathfailed');
             return false;
         }
         if (!is_writable($path)) {
             $this->error('upload_file_system_is_not_writable');
             return false;
         }
     }
     return parent::pre_save($doquery);
 }