id = $id; $this->name = $name; $this->module = $module; // just in case we need to attach file to more than the notes /** BEGIN CONTRIBUTION * Date: 09/07/04 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. * All Rights Reserved. * Contributor(s): SugarCRM Inc. */ $this->folder = '/'.UPLOAD_FOLDER; /** END CONTRIBUTION */ } /** * Upload the file, you are supposed to call SetID after that (once you know it... */ function Upload ($fieldname) { global $root_directory; /** BEGIN CONTRIBUTION * Date: 09/08/04 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. * All Rights Reserved. * Contributor(s): SugarCRM Inc. */ global $upload_badext; /** END CONTRIBUTION */ if (!isset ($_FILES[$fieldname]) || empty ($_FILES[$fieldname]['tmp_name'])) { return true; // uploading an empty file can't fail... } $this->name = $_FILES[$fieldname]['name']; /** BEGIN CONTRIBUTION * Date: 09/07/04 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. * All Rights Reserved. * Contributor(s): SugarCRM Inc. */ if (isset($id)) $this->id = $id; $ext = (strrpos($this->name, ".")) ? substr($this->name, strrpos($this->name, ".") + 1) : NULL; if (in_array($ext, $upload_badext)) { $this->name .= '.txt'; } /** END CONTRIBUTION */ $dest = $root_directory.$this->folder.$this->name; if (!move_uploaded_file($_FILES[$fieldname]['tmp_name'], $dest)) { if (!is_dir($this->folder)) { if (mkdir($root_directory.$this->folder, 0755)) return move_uploaded_file($_FILES[$fieldname]['tmp_name'], $dest); else { // how to handle such error ? die ("ERROR: can't upload $this->name to $this->folder"); } } } return true; } function SetID ($id) { global $root_directory; if (empty ($this->name)) return; if (empty ($id)) die ("id empty"); $this->id = $id; $path = $root_directory.$this->folder; rename ($path.$this->name,$path.$id.$this->name); } function URL () { /** VTIGER CRM CONTRIBUTION BEGINS */ $web_root = $_SERVER['SERVER_NAME']. ":" .$_SERVER['SERVER_PORT']; $web_root = "http://$web_root"; /* VTIGER CRM CONTRIBUTION ENDS */ //global $site_URL; return $web_root.$this->folder.$this->id.rawurlencode($this->name); } /** BEGIN CONTRIBUTION * Date: * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. * All Rights Reserved. * Contributor(s): SugarCRM Inc. */ function Delete ($old_file) { global $root_directory, $upload_dir; return unlink($root_directory . "/" . $upload_dir . $old_file); } /* END CONTRIBUTION */ } ?>