[ Index ] |
|
Code source de vtiger CRM 5.0.2 |
1 <?php 2 /********************************************************************************* 3 * The contents of this file are subject to the SugarCRM Public License Version 1.1.2 4 * ("License"); You may not use this file except in compliance with the 5 * License. You may obtain a copy of the License at http://www.sugarcrm.com/SPL 6 * Software distributed under the License is distributed on an "AS IS" basis, 7 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for 8 * the specific language governing rights and limitations under the License. 9 * The Original Code is: SugarCRM Open Source 10 * The Initial Developer of the Original Code is SugarCRM, Inc.; 11 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.; 12 * All Rights Reserved. 13 * Contributor(s): ______________________________________.. 14 ********************************************************************************/ 15 /********************************************************************************* 16 * $Header $ 17 * Description: 18 ********************************************************************************/ 19 20 require_once ('config.php'); 21 22 23 class UploadFile 24 { 25 26 var $field_name; 27 var $stored_file_name; 28 29 function UploadFile ($field_name) 30 { 31 global $log; 32 $log->debug("Entering UploadFile (".$field_name.") method ..."); 33 $this->field_name = $field_name; 34 $log->debug("Exiting UploadFile method ..."); 35 } 36 37 /** Function to get the url of the attachment 38 * @param $stored_file_name -- stored_file_name:: Type string 39 * @param $bean_id -- bean_id:: Type integer 40 * @returns urlstring -- urlstring:: Type string 41 * 42 */ 43 function get_url($stored_file_name,$bean_id) 44 { 45 global $log; 46 $log->debug("Entering get_url(".$stored_file_name.",".$bean_id.") method ..."); 47 global $site_URL; 48 global $upload_dir; 49 //echo $site_URL.'/'.$upload_dir.$bean_id.$stored_file_name; 50 //echo $_ENV['HOSTNAME'] .':' .$_SERVER["SERVER_PORT"].'/'.$upload_dir.$bean_id.$stored_file_name; 51 $log->debug("Exiting get_url method ..."); 52 return 'http://'.$_ENV['HOSTNAME'] .':' .$_SERVER["SERVER_PORT"].'/'.$upload_dir.$bean_id.$stored_file_name; 53 //return $site_URL.'/'.$upload_dir.$bean_id.$stored_file_name; 54 } 55 56 /** Function to duplicate and copy a file to another location 57 * @param $old_id -- old_id:: Type integer 58 * @param $new_id -- new_id:: Type integer 59 * @param $file_name -- filename:: Type string 60 * 61 */ 62 63 function duplicate_file($old_id, $new_id, $file_name) 64 { 65 global $log; 66 $log->debug("Entering duplicate_file(".$old_id.", ".$new_id.", ".$file_name.") method ..."); 67 global $root_directory; 68 global $upload_dir; 69 $source = $root_directory.'/'.$upload_dir.$old_id.$file_name; 70 $destination = $root_directory.'/'.$upload_dir.$new_id.$file_name; 71 copy( $source,$destination); 72 $log->debug("Exiting duplicate_file method ..."); 73 } 74 75 /** Function to get the status of the file upload 76 * @returns boolean 77 */ 78 79 function confirm_upload() 80 { 81 global $log; 82 $log->debug("Eentering confirm_upload() method ..."); 83 global $root_directory; 84 global $upload_dir; 85 global $upload_maxsize; 86 global $upload_badext; 87 88 89 if (!is_uploaded_file($_FILES[$this->field_name]['tmp_name']) ) 90 { 91 $log->debug("Exiting confirm_upload method ..."); 92 return false; 93 } 94 else if ($_FILES[$this->field_name]['size'] > $upload_maxsize) 95 { 96 die("ERROR: uploaded file was too big: max filesize:$upload_maxsize"); 97 } 98 99 100 if( !is_writable( $root_directory.'/'.$upload_dir)) 101 { 102 die ("ERROR: cannot write to directory: $root_directory/$upload_dir for uploads"); 103 } 104 105 $this->stored_file_name = $this->create_stored_filename(); 106 $log->debug("Exiting confirm_upload method ..."); 107 return true; 108 } 109 110 /** Function to get the stored file name 111 */ 112 113 function get_stored_file_name() 114 { 115 global $log; 116 $log->debug("Entering get_stored_file_name() method ..."); 117 $log->debug("Exiting get_stored_file_name method ..."); 118 return $this->stored_file_name; 119 } 120 121 /** Function to generate a filename for storing 122 */ 123 124 function create_stored_filename() 125 { 126 global $log; 127 $log->debug("Entering create_stored_filename() method ..."); 128 global $upload_badext; 129 $stored_file_name = $_FILES[$this->field_name]['name']; 130 131 $ext_pos = strrpos($stored_file_name, "."); 132 133 $ext = substr($stored_file_name, $ext_pos + 1); 134 135 if (in_array($ext, $upload_badext)) 136 { 137 $stored_file_name .= ".txt"; 138 } 139 $log->debug("Exiting create_stored_filename method ..."); 140 return $stored_file_name; 141 } 142 143 /** Function is to move a file and store it in given location 144 * @param $bean_id -- $bean_id:: Type integer 145 * @returns boolean 146 * 147 */ 148 149 function final_move($bean_id) 150 { 151 global $log; 152 $log->debug("Entering final_move(".$bean_id.") method ..."); 153 global $root_directory; 154 global $upload_dir; 155 156 $file_name = $bean_id.$this->stored_file_name; 157 158 $destination = $root_directory.'/'.$upload_dir.$file_name; 159 160 if (!move_uploaded_file($_FILES[$this->field_name]['tmp_name'], $destination)) 161 { 162 die ("ERROR: can't move_uploaded_file to $destination"); 163 } 164 $log->debug("Exiting final_move method ..."); 165 return true; 166 167 168 } 169 170 /** Function deletes a file for a given file name 171 * @param $bean_id -- bean_id:: Type integer 172 * @param $file_name -- file name:: Type string 173 * @returns boolean 174 * 175 */ 176 177 function unlink_file($bean_id,$file_name) 178 { 179 global $log; 180 $log->debug("Entering unlink_file(".$bean_id.",".$file_name.") method ..."); 181 global $root_directory; 182 global $upload_dir; 183 $log->debug("Exiting unlink_file method ..."); 184 return unlink($root_directory."/".$upload_dir.$bean_id.$file_name); 185 } 186 187 188 } 189 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 10:22:19 2007 | par Balluche grâce à PHPXref 0.7 |