Пример #1
0
 function uploadFile($row_id, $file_field, $upload_folder)
 {
     @($fileName = $_FILES[$file_field]['name']);
     @($tmpName = $_FILES[$file_field]['tmp_name']);
     @($fileSize = $_FILES[$file_field]['size']);
     @($fileType = $_FILES[$file_field]['type']);
     $new_filename = make_filename_safe($fileName);
     if ($this->filename_append_field != "") {
         if ($_REQUEST[$this->filename_append_field] != '') {
             $new_filename = $_REQUEST[$this->filename_append_field] . "_" . $new_filename;
         } else {
             if ($this->filename_append_field == $this->db_table_pk) {
                 $new_filename = $row_id . "_" . $new_filename;
             } else {
                 @($db_value_to_append = q1("SELECT {$this->filename_append_field} FROM {$this->db_table} WHERE {$this->db_table_pk} = {$row_id}"));
                 if ($db_value_to_append != "") {
                     $new_filename = $db_value_to_append . "_" . $new_filename;
                 }
             }
         }
     }
     $destination = $upload_folder . $new_filename;
     $success = move_uploaded_file($tmpName, $destination);
     if ($success) {
         $update_success = qr("UPDATE {$this->db_table} SET {$file_field} = \"{$new_filename}\" WHERE {$this->db_table_pk} = {$row_id}");
         if ($this->onFileUploadExecuteCallBackFunction != '') {
             $file_info_array = array();
             $file_info_array[id] = $row_id;
             $file_info_array[field] = $file_field;
             $file_info_array[fileName] = $new_filename;
             $file_info_array[fileSize] = $fileSize;
             $file_info_array[fldType] = $fldType;
             call_user_func($this->onFileUploadExecuteCallBackFunction, $file_info_array);
         }
     }
     if ($update_success) {
         return true;
         //$report_msg[] = "File Uploaded.";
     } else {
         return false;
         //$error_msg[] = "There was an error uploading your file (or none was selected).";
     }
 }
Пример #2
0
 function uploadFile($row_id, $file_field, $upload_folder, $allowedExts = "")
 {
     global $report_msg, $error_msg;
     @($fileName = $_FILES[$file_field]['name']);
     @($tmpName = $_FILES[$file_field]['tmp_name']);
     @($fileSize = $_FILES[$file_field]['size']);
     @($fileType = $_FILES[$file_field]['type']);
     if (is_array($allowedExts)) {
         $fileExt = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
         //gets file ext (lowercase)
         if (!in_array($fileExt, $allowedExts)) {
             $error_msg[] = "Upload failed. Selected file was extention <b>.{$fileExt}</b> but this is not an permitted file extension.";
             return false;
         }
     }
     $new_filename = make_filename_safe($fileName);
     if ($this->filename_append_field != "") {
         if ($_REQUEST[$this->filename_append_field] != '') {
             $new_filename = $_REQUEST[$this->filename_append_field] . "_" . $new_filename;
         } else {
             if ($this->filename_append_field == $this->db_table_pk) {
                 $new_filename = $row_id . "_" . $new_filename;
             } else {
                 @($db_value_to_append = q1("SELECT {$this->filename_append_field} FROM {$this->db_table} WHERE {$this->db_table_pk} = {$row_id}"));
                 if ($db_value_to_append != "") {
                     $new_filename = $db_value_to_append . "_" . $new_filename;
                 }
             }
         }
     }
     $destination = $upload_folder . $new_filename;
     $success = move_uploaded_file($tmpName, $destination);
     if ($success) {
         $update_success = qr("UPDATE {$this->db_table} SET {$file_field} = \"{$new_filename}\" WHERE {$this->db_table_pk} = {$row_id}");
         if ($this->onFileUploadExecuteCallBackFunction != '') {
             $file_info_array = array();
             $file_info_array[id] = $row_id;
             $file_info_array[field] = $file_field;
             $file_info_array[fileName] = $new_filename;
             $file_info_array[fileSize] = $fileSize;
             $file_info_array[fldType] = $fldType;
             call_user_func($this->onFileUploadExecuteCallBackFunction, $file_info_array);
         }
         if ($update_success) {
             return true;
         }
     } else {
         $error_msg[] = "There was an error uploading your file. Check permissions of the destination directory (make sure is set to 777).";
     }
     return false;
 }