예제 #1
0
 function upload_process($type_id = '0')
 {
     $attach_info = array();
     //init moved here
     if (empty($this->upload_dir)) {
         $this->upload_dir = gmdate("Y") . DS . gmdate("m") . DS . gmdate("d");
     }
     $this->out_file_path = PHPB2B_ROOT . $this->attachment_dir . DS . $this->upload_dir . DS;
     $this->upload_url = str_replace(array(DS, "\\", "\\'"), "/", $this->upload_dir) . '/';
     if (isset($_FILES) && $_FILES[$this->upload_form_field]['size'] > 0) {
         $mimetype = new mimetype();
         $file_ext = strtolower(fileext($_FILES[$this->upload_form_field]['name']));
         if ($this->is_image) {
             //check image format
             if (!in_array($file_ext, $this->imgext)) {
                 return L("format_not_support");
             }
         }
         if (in_array($file_ext, $this->imgext)) {
             $this->is_image = 1;
             $this->allowed_file_ext = $this->imgext;
             if (!in_array($_FILES[$this->upload_form_field]['type'], $mimetype->image_mimes)) {
                 flash("format_not_support", '', 0);
             }
         }
         require LIB_PATH . "upload.class.php";
         $upload = new FileUploads();
         $upload->upload_dir = $this->out_file_path;
         $upload->extensions = $this->allowed_file_ext;
         $upload->max_file_size = $this->max_file_size;
         $upload->the_temp_file = $_FILES[$this->upload_form_field]['tmp_name'];
         $upload->the_file = $_FILES[$this->upload_form_field]['name'];
         $upload->http_error = $_FILES[$this->upload_form_field]['error'];
         if ($_FILES[$this->upload_form_field]['size'] > $this->max_file_size) {
             flash("file_too_big", '', 0, implode(",", $this->allowed_file_ext));
         }
         $isuploaded = $upload->upload($this->rename_file);
         if (!$isuploaded) {
             flash("file_too_big", '', 0, implode(",", $this->allowed_file_ext));
         }
         //insert into db.
         //$_this = & Attachments::getInstance();
         $_this = Attachments::getInstance();
         $this->file_full_url = $this->upload_url . $upload->file_copy;
         $this->file_size = $_FILES[$this->upload_form_field]['size'];
         $this->out_file_name = $upload->file_copy;
         $this->out_file_full_path = $this->out_file_path . $this->out_file_name;
         if ($this->is_image) {
             list($width, $height) = @getimagesize($this->out_file_full_path);
             $this->width = intval($width);
             $this->height = intval($height);
             if ($this->if_orignal) {
                 copy($this->out_file_full_path, $this->out_file_path . $this->rename_file . $this->orignal_file_ext . $upload->file_extension);
             }
             if ($this->if_thumb) {
                 require LIB_PATH . "thumb.class.php";
                 if ($this->if_orignal) {
                     $img = new Image($this->out_file_path . $this->rename_file . $this->orignal_file_ext . $upload->file_extension, $this->out_file_full_path);
                 } else {
                     $img = new Image($this->out_file_path . $this->rename_file . $upload->file_extension, $this->out_file_full_path);
                 }
                 if ($this->if_thumb_middle) {
                     list($width, $height) = $this->getScale("middle");
                     $img->Thumb($width, $height, '.middle.jpg');
                 }
                 list($width, $height) = $this->getScale("small");
                 $img->Thumb($width, $height);
             }
             if ($this->if_watermark) {
                 $markimg = new ImageWatermark($file_name = $this->out_file_path . $this->rename_file . $upload->file_extension);
                 $markimg->fontFile = DATA_PATH . "fonts/" . $this->fontFace;
                 if ($this->is_water_image) {
                     $markimg->appendImageMark(PHPB2B_ROOT . STATICURL . 'images/watermark.png');
                 } else {
                     $waterText = !empty($this->is_water_text) ? $this->is_water_text : pb_getenv('HTTP_HOST');
                     $markimg->color = !empty($this->water_text_color) ? $this->water_text_color : '#FF0000';
                     $markimg->angle = 0;
                     //rotate for textwatermark.
                     $markimg->appendTextMark($waterText);
                 }
                 if ($this->width > 150 || $this->height > 150) {
                     $markimg->write($file_name);
                 }
             }
             if ($this->if_thumb_large) {
                 list($width, $height) = $this->getScale("large");
                 $img->Thumb($width, $height, null);
             }
         }
         //save
         if ($this->insert_new) {
             $attach_info['attachment'] = $this->file_full_url;
             $attach_info['created'] = $attach_info['modified'] = $_this->timestamp;
             $attach_info['title'] = empty($this->title) ? reset(explode(".", $upload->the_file)) : $this->title;
             $attach_info['description'] = $this->description;
             $attach_info['file_name'] = $upload->the_file;
             $attach_info['file_name'] = $this->is_image;
             $attach_info['file_size'] = $_FILES[$this->upload_form_field]['size'];
             $attach_info['file_type'] = $_FILES[$this->upload_form_field]['type'];
             $attach_info['attachmenttype_id'] = $type_id;
             if (!empty($GLOBALS['pb_user'])) {
                 $attach_info['member_id'] = intval($GLOBALS['pb_user']['pb_userid']);
             }
             $this->id = $_this->Add($attach_info);
         }
     }
 }
예제 #2
0
 function upload_process($type_id = '0')
 {
     $attach_info = array();
     if (isset($_FILES) && $_FILES[$this->upload_form_field]['size'] > 0) {
         $mimetype = new mimetype();
         if (in_array($file_ext = fileext($_FILES[$this->upload_form_field]['name']), $this->imgext)) {
             $this->is_image = 1;
             $this->allowed_file_ext = $this->imgext;
             if (!in_array($_FILES[$this->upload_form_field]['type'], $mimetype->image_mimes)) {
                 flash("format_not_support", '', 0);
             }
         }
         require LIB_PATH . "upload.class.php";
         $upload = new FileUploads();
         $upload->upload_dir = $this->out_file_path;
         $upload->extensions = $this->allowed_file_ext;
         $upload->max_file_size = $this->max_file_size;
         $upload->the_temp_file = $_FILES[$this->upload_form_field]['tmp_name'];
         $upload->the_file = $_FILES[$this->upload_form_field]['name'];
         $upload->http_error = $_FILES[$this->upload_form_field]['error'];
         if ($_FILES[$this->upload_form_field]['size'] > $this->max_file_size) {
             flash("file_too_big", '', 0, implode(",", $this->allowed_file_ext));
         }
         $isuploaded = $upload->upload($this->rename_file);
         if (!$isuploaded) {
             flash("file_too_big", '', 0, implode(",", $this->allowed_file_ext));
         }
         //insert into db.
         $_this =& Attachments::getInstance();
         $this->file_full_url = $this->upload_url . $upload->file_copy;
         $this->file_size = $_FILES[$this->upload_form_field]['size'];
         $this->out_file_name = $upload->file_copy;
         $this->out_file_full_path = $this->out_file_path . $this->out_file_name;
         $this->file_name = $upload->the_file;
         if ($this->is_image) {
             list($width, $height) = @getimagesize($this->out_file_full_path);
             $this->width = intval($width);
             $this->height = intval($height);
             if ($this->if_orignal) {
                 copy($this->out_file_full_path, $this->out_file_path . $this->rename_file . $this->orignal_file_ext . $upload->file_extension);
             }
             if ($this->if_thumb) {
                 require LIB_PATH . "thumb.class.php";
                 if ($this->if_orignal) {
                     $img = new Image($this->out_file_path . $this->rename_file . $this->orignal_file_ext . $upload->file_extension, $this->out_file_full_path);
                 } else {
                     $img = new Image($this->out_file_path . $this->rename_file . $upload->file_extension, $this->out_file_full_path);
                 }
                 if ($this->if_thumb_middle) {
                     list($width, $height) = $this->getScale("middle");
                     $img->Thumb($width, $height, '.middle.jpg');
                 }
                 list($width, $height) = $this->getScale("small");
                 $img->Thumb($width, $height);
             }
             if ($this->if_watermark) {
                 $markimg = new ImageWatermark($file_name = $this->out_file_path . $this->rename_file . $upload->file_extension);
                 $markimg->fontFile = APP_ROOT . "data/fonts/" . $this->fontFace;
                 if ($this->is_water_image) {
                     $markimg->appendImageMark(APP_ROOT . 'images/watermark.png');
                 } else {
                     $waterText = !empty($this->is_water_text) ? $this->is_water_text : URL;
                     $markimg->color = !empty($this->water_text_color) ? $this->water_text_color : '#FF0000';
                     $markimg->angle = 45;
                     $markimg->appendTextMark($waterText);
                 }
                 if ($this->width > 150 || $this->height > 150) {
                     $markimg->write($file_name);
                 }
             }
             if ($this->if_thumb_large) {
                 list($width, $height) = $this->getScale("large");
                 $img->Thumb($width, $height, null);
             }
         }
         //save
         if ($this->insert_new) {
             $attach_info['attachment'] = $this->file_full_url;
             $attach_info['created'] = $attach_info['modified'] = $_this->timestamp;
             $attach_info['title'] = empty($this->title) ? reset(explode(".", $upload->the_file)) : $this->title;
             $attach_info['description'] = $this->description;
             $attach_info['file_name'] = $upload->the_file;
             $attach_info['is_image'] = $this->is_image;
             $attach_info['file_size'] = $_FILES[$this->upload_form_field]['size'];
             $attach_info['file_type'] = $_FILES[$this->upload_form_field]['type'];
             $attach_info['attachmenttype_id'] = $type_id;
             if (isset($_SESSION['MemberID'])) {
                 $attach_info['member_id'] = intval($_SESSION['MemberID']);
             }
             $this->id = $_this->Add($attach_info);
         }
     }
 }