/** * insert uploaded files to database is done AFTER moving the * file to the appropriate project directory * * overwrites original insert function of DbProjectItem * */ public function insert() { $upload_filepath = confGet('DIR_TEMP') . 'uploads/' . $this->tmp_filename; if (!file_exists($upload_filepath)) { trigger_error("Uploaded field no longer exists in {$upload_filepath}", E_USER_WARNING); return NULL; } if (!file_exists(confGet('DIR_FILES'))) { trigger_error("Directory for files '" . confGet('DIR_FILES') . "' does not exists", E_USER_WARNING); return NULL; } ### create project directory ### $this->tmp_dir = "prj{$this->project}"; if (!file_exists(confGet('DIR_FILES') . $this->tmp_dir)) { if (!mkdir(confGet('DIR_FILES') . $this->tmp_dir, 0777)) { trigger_error("could not create target directory for uploaded file '" . confGet('DIR_FILES') . $this->tmp_dir . "/'", E_USER_WARNING); return NULL; } } /** * insert into DB to get the item-id as prefix for temp-name * * This has to be done before moving the file, because we need the * new item id for the filename. */ if (!parent::insert() || !$this->id) { trigger_error("inserting file object failed"); return NULL; } $this->tmp_filename = $this->id . "_" . $this->tmp_filename; ### use original function to write to Db parent::update(); ### move file ### if (!rename($upload_filepath, confGet('DIR_FILES') . $this->tmp_dir . "/" . $this->tmp_filename)) { trigger_error("could not move uploaded file from '{$upload_filepath}' to '" . confGet('DIR_FILES') . $this->tmp_dir . "/" . $this->tmp_filename . "'", E_USER_WARNING); ### remove invalid database entry ### $this->DeleteFromDb(); return NULL; } return true; }