--- /dev/null
+<?php
+/**
+ * ACS File
+ *
+ * @author kuwayama
+ * @version $Revision: 1.35 $ $Date: 2006/12/18 07:41:48 $
+ */
+require_once(ACS_CLASS_DIR . 'ACSFileInfoModel.class.php');
+require_once(ACS_CLASS_DIR . 'ACSFileAccessHistoryModel.class.php');
+class ACSFile
+{
+ /* ¥Õ¥¡¥¤¥ëID */
+ var $file_id;
+
+ /* ¥ª¡¼¥Ê¡¼¥³¥ß¥å¥Ë¥Æ¥£ID */
+ var $owner_community_id;
+
+ /* ɽ¼¨ÍÑ¥Õ¥¡¥¤¥ë̾ */
+ var $display_file_name;
+
+ /* ¥µ¡¼¥Ð¥Õ¥¡¥¤¥ë̾ */
+ var $server_file_name;
+
+ /* ¥µ¥à¥Í¥¤¥ë¥µ¡¼¥Ð¥Õ¥¡¥¤¥ë̾ */
+ var $thumbnail_server_file_name;
+
+ /* RSS¥µ¡¼¥Ð¥Õ¥¡¥¤¥ë̾ */
+ var $rss_server_file_name;
+
+ /* MIME TYPE */
+ var $mime_type;
+
+ /* ¥Õ¥¡¥¤¥ë¥µ¥¤¥º */
+ var $file_size;
+
+ /* ÅÐÏ¿¥æ¡¼¥¶¥³¥ß¥å¥Ë¥Æ¥£ID */
+ var $entry_user_community_id;
+
+ /* ÅÐÏ¿¥æ¡¼¥¶¥³¥ß¥å¥Ë¥Æ¥£Ì¾ */
+ var $entry_user_community_name;
+
+ /* ÅÐÏ¿Æü */
+ var $entry_date;
+
+ /* ¹¹¿·¥æ¡¼¥¶¥³¥ß¥å¥Ë¥Æ¥£ID */
+ var $update_user_community_id;
+
+ /* ¹¹¿·¥æ¡¼¥¶¥³¥ß¥å¥Ë¥Æ¥£Ì¾ */
+ var $update_user_community_name;
+
+ /* ¹¹¿·Æü */
+ var $update_date;
+
+ /* ¥¢¥Ã¥×¥í¡¼¥É¥Æ¥ó¥Ý¥é¥ê¥Õ¥¡¥¤¥ë̾ */
+ var $upload_temp_file_name;
+
+ /**
+ * ¥³¥ó¥¹¥È¥é¥¯¥¿
+ *
+ * @param $file_info_row
+ */
+ function ACSFile ($file_info_row) {
+ $this->set_file_info($file_info_row);
+ }
+
+ /**
+ * ¥Õ¥¡¥¤¥ë¾ðÊ󥻥åÈ
+ *
+ * @param $file_info_row
+ */
+ function set_file_info ($file_info_row) {
+ $this->set_file_id($file_info_row['file_id']);
+ $this->set_owner_community_id($file_info_row['owner_community_id']);
+ $this->set_display_file_name($file_info_row['display_file_name']);
+ $this->set_server_file_name($file_info_row['server_file_name']);
+ $this->set_thumbnail_server_file_name($file_info_row['thumbnail_server_file_name']);
+ $this->set_rss_server_file_name($file_info_row['rss_server_file_name']);
+ $this->set_mime_type($file_info_row['mime_type']);
+ $this->set_file_size($file_info_row['file_size']);
+ $this->set_entry_user_community_id($file_info_row['entry_user_community_id']);
+ $this->set_entry_user_community_name($file_info_row['entry_user_community_name']);
+ $this->set_entry_date($file_info_row['entry_date']);
+ $this->set_update_user_community_id($file_info_row['update_user_community_id']);
+ $this->set_update_user_community_name($file_info_row['update_user_community_name']);
+ $this->set_update_date($file_info_row['update_date']);
+
+ // ¥¢¥Ã¥×¥í¡¼¥É»þ¤ËɬÍ×
+ $this->set_upload_temp_file_name($file_info_row['upload_temp_file_name']);
+ }
+
+ /**
+ * ¥¤¥ó¥¹¥¿¥ó¥¹¼èÆÀ¡Ê¥Õ¥¡¥¤¥ëID»ØÄê¡Ë
+ *
+ * @param $file_id
+ */
+ static function get_file_info_instance ($file_id) {
+ $file_info_row = ACSFileInfoModel::select_file_info_row($file_id);
+ $file_obj = new ACSFile($file_info_row);
+
+ return $file_obj;
+ }
+
+
+ /**
+ * ¥¤¥ó¥¹¥¿¥ó¥¹¼èÆÀ¡Ê¥¢¥Ã¥×¥í¡¼¥ÉÍÑ¡Ë
+ *
+ * @param $upload_file_info_row $_FILES['new_file']
+ * @param $owner_community_id ÂоݤȤʤ륳¥ß¥å¥Ë¥Æ¥£ID
+ * @param $acs_user_community_id ¥¢¥Ã¥×¥í¡¼¥É¤·¤¿¥æ¡¼¥¶¥³¥ß¥å¥Ë¥Æ¥£ID
+ * @param $file_id ´û¸¥Õ¥¡¥¤¥ë¤Î¹¹¿·»þ¤Î¥Õ¥¡¥¤¥ëID
+ */
+ static function get_upload_file_info_instance ($upload_file_info_row, $owner_community_id, $acs_user_community_id, $file_id = "") {
+ $file_info_row = array();
+ /* file_id ¼èÆÀ */
+ if($file_id == ""){
+ $file_id = ACSFileInfoModel::get_next_file_id_seq();
+ }
+
+ /* display_file_name */
+ if (!ini_get('mbstring.encoding_translation')) {
+ $display_file_name = mb_convert_encoding($upload_file_info_row['name'], mb_internal_encoding(), mb_http_output());
+ } else {
+ $display_file_name = $upload_file_info_row['name'];
+ }
+ /* server_file_name ºîÀ® */
+ $server_file_name = ACSFile::get_upload_file_save_file_name($owner_community_id, $file_id);
+
+ /* thumbnail_server_file_name ºîÀ® */
+ $thumbnail_server_file_name = ACSFile::get_thumbnail_save_file_name($owner_community_id, $file_id);
+ /* ºîÀ®Æü */
+ $filemtime = filemtime($upload_file_info_row['tmp_name']);
+
+ // insert ÍѤ˥ե©¡¼¥Þ¥Ã¥È¤¹¤ë
+ $entry_date = ACSLib::convert_timestamp_to_pg_date($filemtime);
+
+ /* ¹¹¿·Æü */
+ $update_date = $entry_date;
+
+ $file_info_row['file_id'] = $file_id;
+ $file_info_row['owner_community_id'] = $owner_community_id;
+ $file_info_row['display_file_name'] = $display_file_name;
+ $file_info_row['server_file_name'] = $server_file_name;
+ $file_info_row['thumbnail_server_file_name'] = $thumbnail_server_file_name;
+ $file_info_row['mime_type'] = $upload_file_info_row['type'];
+ $file_info_row['file_size'] = $upload_file_info_row['size'];
+ $file_info_row['entry_user_community_id'] = $acs_user_community_id;
+ $file_info_row['entry_date'] = $entry_date;
+ $file_info_row['update_user_community_id'] = $acs_user_community_id;
+ $file_info_row['update_date'] = $update_date;
+
+ $file_info_row['upload_temp_file_name'] = $upload_file_info_row['tmp_name'];
+
+ $file_obj = new ACSFile($file_info_row);
+ return $file_obj;
+ }
+
+ /**
+ * ¥¤¥ó¥¹¥¿¥ó¥¹¼èÆÀ¡ÊÍúÎò¹¹¿·¥¢¥Ã¥×¥í¡¼¥ÉÍÑ¡Ë
+ *
+ * @param $upload_file_info_row $_FILES['new_file']
+ * @param $owner_community_id ÂоݤȤʤ륳¥ß¥å¥Ë¥Æ¥£ID
+ * @param $acs_user_community_id ¥¢¥Ã¥×¥í¡¼¥É¤·¤¿¥æ¡¼¥¶¥³¥ß¥å¥Ë¥Æ¥£ID
+ * @param $file_id ´û¸¥Õ¥¡¥¤¥ë¤Î¹¹¿·»þ¤Î¥Õ¥¡¥¤¥ëID
+ */
+ static function get_upload_file_info_instance_for_update($upload_file_info_row, $owner_community_id, $acs_user_community_id, $file_id) {
+ $file_info_row = array();
+
+ /* ¿·file_id¼èÆÀ (server_file_nameÍÑ) */
+ $new_file_id = ACSFileInfoModel::get_next_file_id_seq();
+
+ /* display_file_name */
+ if (!ini_get('mbstring.encoding_translation')) {
+ $display_file_name = mb_convert_encoding($upload_file_info_row['name'], mb_internal_encoding(), mb_http_output());
+ } else {
+ $display_file_name = $upload_file_info_row['name'];
+ }
+ /* server_file_name ºîÀ® */
+ $server_file_name = ACSFile::get_upload_file_save_file_name($owner_community_id, $new_file_id);
+
+ /* thumbnail_server_file_name ºîÀ® */
+ $thumbnail_server_file_name = ACSFile::get_thumbnail_save_file_name($owner_community_id, $new_file_id);
+ /* ºîÀ®Æü */
+ $filemtime = filemtime($upload_file_info_row['tmp_name']);
+
+ // insert ÍѤ˥ե©¡¼¥Þ¥Ã¥È¤¹¤ë
+ $entry_date = ACSLib::convert_timestamp_to_pg_date($filemtime);
+
+ /* ¹¹¿·Æü */
+ $update_date = $entry_date;
+
+ $file_info_row['file_id'] = $file_id;
+ $file_info_row['owner_community_id'] = $owner_community_id;
+ $file_info_row['display_file_name'] = $display_file_name;
+ $file_info_row['server_file_name'] = $server_file_name;
+ $file_info_row['thumbnail_server_file_name'] = $thumbnail_server_file_name;
+ $file_info_row['mime_type'] = $upload_file_info_row['type'];
+ $file_info_row['file_size'] = $upload_file_info_row['size'];
+ $file_info_row['entry_user_community_id'] = $acs_user_community_id;
+ $file_info_row['entry_date'] = $entry_date;
+ $file_info_row['update_user_community_id'] = $acs_user_community_id;
+ $file_info_row['update_date'] = $update_date;
+
+ $file_info_row['upload_temp_file_name'] = $upload_file_info_row['tmp_name'];
+
+ $file_obj = new ACSFile($file_info_row);
+ return $file_obj;
+ }
+
+ /**
+ * ¥Õ¥¡¥¤¥ëID¥»¥Ã¥È
+ *
+ * @param $file_id
+ */
+ function set_file_id ($file_id) {
+ $this->file_id = $file_id;
+ }
+
+ /**
+ * ¥Õ¥¡¥¤¥ëID¥²¥Ã¥È
+ *
+ * @param none
+ */
+ function get_file_id () {
+ return $this->file_id;
+ }
+
+ /**
+ * ¥ª¡¼¥Ê¡¼¥³¥ß¥å¥Ë¥Æ¥£ID¥»¥Ã¥È
+ *
+ * @param $owner_community_id
+ */
+ function set_owner_community_id ($owner_community_id) {
+ $this->owner_community_id = $owner_community_id;
+ }
+
+ /**
+ * ¥ª¡¼¥Ê¡¼¥³¥ß¥å¥Ë¥Æ¥£ID¥²¥Ã¥È
+ *
+ * @param none
+ */
+ function get_owner_community_id () {
+ return $this->owner_community_id;
+ }
+
+ /**
+ * ɽ¼¨ÍÑ¥Õ¥¡¥¤¥ë̾¥»¥Ã¥È
+ *
+ * @param $file_name
+ */
+ function set_display_file_name ($file_name) {
+ $this->display_file_name = $file_name;
+ }
+
+ /**
+ * ɽ¼¨ÍÑ¥Õ¥¡¥¤¥ë̾¥²¥Ã¥È
+ *
+ * @param none
+ */
+ function get_display_file_name () {
+ return $this->display_file_name;
+ }
+
+ /**
+ * ¥µ¡¼¥Ð¥Õ¥¡¥¤¥ë̾¥»¥Ã¥È
+ *
+ * @param $server_file_name
+ */
+ function set_server_file_name ($server_file_name) {
+ $this->server_file_name = $server_file_name;
+ }
+
+ /**
+ * ¥µ¡¼¥Ð¥Õ¥¡¥¤¥ë̾¥²¥Ã¥È
+ *
+ * @param none
+ */
+ function get_server_file_name () {
+ return $this->server_file_name;
+ }
+
+ /**
+ * ¥µ¥à¥Í¥¤¥ë¥µ¡¼¥Ð¥Õ¥¡¥¤¥ë̾¥»¥Ã¥È
+ *
+ * @param $thumbnail_server_file_name
+ */
+ function set_thumbnail_server_file_name ($thumbnail_server_file_name) {
+ $this->thumbnail_server_file_name = $thumbnail_server_file_name;
+ }
+
+ /**
+ * ¥µ¥à¥Í¥¤¥ë¥µ¡¼¥Ð¥Õ¥¡¥¤¥ë̾¥²¥Ã¥È
+ *
+ * @param none
+ */
+ function get_thumbnail_server_file_name () {
+ return $this->thumbnail_server_file_name;
+ }
+
+ /**
+ * RSS¥µ¡¼¥Ð¥Õ¥¡¥¤¥ë̾¥»¥Ã¥È
+ *
+ * @param $rss_server_file_name
+ */
+ function set_rss_server_file_name ($rss_server_file_name) {
+ $this->rss_server_file_name = $rss_server_file_name;
+ }
+
+ /**
+ * RSS¥µ¡¼¥Ð¥Õ¥¡¥¤¥ë̾¥²¥Ã¥È
+ *
+ * @param none
+ */
+ function get_rss_server_file_name () {
+ return $this->rss_server_file_name;
+ }
+
+ /**
+ * MIME TYPE ¥»¥Ã¥È
+ *
+ * @param $mime_type
+ */
+ function set_mime_type ($mime_type) {
+ $this->mime_type = $mime_type;
+ }
+
+ /**
+ * MIME TYPE ¥²¥Ã¥È
+ *
+ * @param none
+ */
+ function get_mime_type () {
+ return $this->mime_type;
+ }
+
+ /**
+ * ¥Õ¥¡¥¤¥ë¥µ¥¤¥º¥»¥Ã¥È
+ *
+ * @param $file_size
+ */
+ function set_file_size ($file_size) {
+ $this->file_size = $file_size;
+ }
+
+ /**
+ * ¥Õ¥¡¥¤¥ë¥µ¥¤¥º¥²¥Ã¥È
+ *
+ * @param none
+ */
+ function get_file_size () {
+ return $this->file_size;
+ }
+
+ /**
+ * ¥Õ¥¡¥¤¥ë¥µ¥¤¥º¥²¥Ã¥È (KB)
+ *
+ * @param none
+ */
+ function get_file_size_kb () {
+ $size = $this->file_size / 1024;
+ return number_format(ceil($size)) . " KB";
+ }
+
+ /**
+ * ¥¢¥Ã¥×¥í¡¼¥É¥Æ¥ó¥Ý¥é¥ê¥Õ¥¡¥¤¥ë̾¥»¥Ã¥È
+ *
+ * @param $upload_temp_file_name
+ */
+ function set_upload_temp_file_name ($upload_temp_file_name) {
+ $this->upload_temp_file_name = $upload_temp_file_name;
+ }
+
+ /**
+ * ¥¢¥Ã¥×¥í¡¼¥É¥Æ¥ó¥Ý¥é¥ê¥Õ¥¡¥¤¥ë̾¥²¥Ã¥È
+ *
+ * @param none
+ */
+ function get_upload_temp_file_name () {
+ return $this->upload_temp_file_name;
+ }
+
+ /**
+ * ÅÐÏ¿¼Ô¥æ¡¼¥¶¥³¥ß¥å¥Ë¥Æ¥£ID¥»¥Ã¥È
+ *
+ * @param $entry_user_community_id
+ */
+ function set_entry_user_community_id ($entry_user_community_id) {
+ $this->entry_user_community_id = $entry_user_community_id;
+ }
+
+ /**
+ * ÅÐÏ¿¼Ô¥æ¡¼¥¶¥³¥ß¥å¥Ë¥Æ¥£ID¥²¥Ã¥È
+ *
+ * @param none
+ */
+ function get_entry_user_community_id () {
+ return $this->entry_user_community_id;
+ }
+
+ /**
+ * ÅÐÏ¿¼Ô¥æ¡¼¥¶¥³¥ß¥å¥Ë¥Æ¥£Ì¾¥»¥Ã¥È
+ *
+ * @param $entry_user_community_name
+ */
+ function set_entry_user_community_name ($entry_user_community_name) {
+ $this->entry_user_community_name = $entry_user_community_name;
+ }
+
+ /**
+ * ÅÐÏ¿¼Ô¥æ¡¼¥¶¥³¥ß¥å¥Ë¥Æ¥£Ì¾¥²¥Ã¥È
+ *
+ * @param none
+ */
+ function get_entry_user_community_name () {
+ return $this->entry_user_community_name;
+ }
+
+ /**
+ * ÅÐÏ¿Æü¥»¥Ã¥È
+ *
+ * @param $entry_date
+ */
+ function set_entry_date ($entry_date) {
+ $this->entry_date = $entry_date;
+ }
+
+ /**
+ * ÅÐÏ¿Æü¥²¥Ã¥È
+ *
+ * @param none
+ */
+ function get_entry_date () {
+ return $this->entry_date;
+ }
+
+ /**
+ * ÅÐÏ¿Æü¥²¥Ã¥È (yyyymmddhmi)
+ *
+ * @param none
+ */
+ function get_entry_date_yyyymmddhmi () {
+ $date_yyyymmddhmi = ACSLib::convert_pg_date_to_str($this->entry_date);
+ return $date_yyyymmddhmi;
+ }
+
+ /**
+ * ¹¹¿·¼Ô¥æ¡¼¥¶¥³¥ß¥å¥Ë¥Æ¥£ID¥»¥Ã¥È
+ *
+ * @param $update_user_community_id
+ */
+ function set_update_user_community_id ($update_user_community_id) {
+ $this->update_user_community_id = $update_user_community_id;
+ }
+
+ /**
+ * ¹¹¿·¼Ô¥æ¡¼¥¶¥³¥ß¥å¥Ë¥Æ¥£ID¥²¥Ã¥È
+ *
+ * @param none
+ */
+ function get_update_user_community_id () {
+ return $this->update_user_community_id;
+ }
+
+ /**
+ * ¹¹¿·¼Ô¥æ¡¼¥¶¥³¥ß¥å¥Ë¥Æ¥£Ì¾¥»¥Ã¥È
+ *
+ * @param $update_user_community_name
+ */
+ function set_update_user_community_name ($update_user_community_name) {
+ $this->update_user_community_name = $update_user_community_name;
+ }
+
+ /**
+ * ¹¹¿·¼Ô¥æ¡¼¥¶¥³¥ß¥å¥Ë¥Æ¥£Ì¾¥²¥Ã¥È
+ *
+ * @param none
+ */
+ function get_update_user_community_name () {
+ return $this->update_user_community_name;
+ }
+
+ /**
+ * ¹¹¿·Æü¥»¥Ã¥È
+ *
+ * @param $update_date
+ */
+ function set_update_date ($update_date) {
+ $this->update_date = $update_date;
+ }
+
+ /**
+ * ¹¹¿·Æü¥²¥Ã¥È
+ *
+ * @param none
+ */
+ function get_update_date () {
+ return $this->update_date;
+ }
+
+ /**
+ * ¹¹¿·Æü¥²¥Ã¥È (yyyymmddhmi)
+ *
+ * @param none
+ */
+ function get_update_date_yyyymmddhmi () {
+ $date_yyyymmddhmi = ACSLib::convert_pg_date_to_str($this->update_date);
+ return $date_yyyymmddhmi;
+ }
+
+ /**
+ * ¥¢¥Ã¥×¥í¡¼¥É¥Õ¥¡¥¤¥ëÊݸÀè¥Ñ¥¹
+ *
+ * @param $owner_community_id
+ * @param $file_id
+ */
+ function get_upload_file_save_file_name ($owner_community_id, $file_id) {
+ //$upload_file_save_file_name = ACS_FOLDER_DIR;
+ //$upload_file_save_file_name .= '/';
+ //$upload_file_save_file_name .= $owner_community_id;
+ //$upload_file_save_file_name .= '/';
+
+ $upload_file_save_file_name = ACSFile::get_upload_file_save_path($owner_community_id);
+ $upload_file_save_file_name .= $file_id;
+
+ return $upload_file_save_file_name;
+ }
+
+ /**
+ * ¥¢¥Ã¥×¥í¡¼¥É¥Õ¥¡¥¤¥ëÊݸÀè¥Ç¥£¥ì¥¯¥È¥ê
+ * ¥Õ¥¡¥¤¥ë³ÊǼÀè¥ë¡¼¥È¥Ñ¥¹ / ¥æ¡¼¥¶¥³¥ß¥å¥Ë¥Æ¥£ID / ¥Õ¥¡¥¤¥ë̾ (file_id)
+ *
+ * @param $owner_community_id
+ */
+ static function get_upload_file_save_path ($owner_community_id) {
+ //$upload_file_save_path = ACS_FOLDER_DIR;
+ //$upload_file_save_path .= '/';
+ $upload_file_save_path = $owner_community_id;
+ $upload_file_save_path .= '/';
+
+ return $upload_file_save_path;
+ }
+
+ /**
+ * ¥µ¥à¥Í¥¤¥ë²èÁü¥Õ¥¡¥¤¥ë̾
+ * ¥Õ¥¡¥¤¥ë³ÊǼÀè¥ë¡¼¥È¥Ñ¥¹ / ¥æ¡¼¥¶¥³¥ß¥å¥Ë¥Æ¥£ID / ¥Õ¥¡¥¤¥ë̾ (file_id.thumb)
+ *
+ * @param $owner_community_id
+ * @param $file_id
+ */
+ static function get_thumbnail_save_file_name ($owner_community_id, $file_id) {
+ $thumnail_save_file_name = ACSFile::get_upload_file_save_path($owner_community_id);
+ $thumnail_save_file_name .= $file_id;
+ $thumnail_save_file_name .= '.thumb';
+ return $thumnail_save_file_name;
+ }
+
+ /**
+ * RSS¥µ¥à¥Í¥¤¥ë²èÁü¥Õ¥¡¥¤¥ë̾
+ * ¥Õ¥¡¥¤¥ë³ÊǼÀè¥ë¡¼¥È¥Ñ¥¹ / ¥æ¡¼¥¶¥³¥ß¥å¥Ë¥Æ¥£ID / ¥Õ¥¡¥¤¥ë̾ (file_id.rss)
+ *
+ * @param $owner_community_id
+ * @param $file_id
+ */
+ function get_rss_save_file_name ($owner_community_id, $file_id) {
+ $rss_save_file_name = ACSFile::get_upload_file_save_path($owner_community_id);
+ $rss_save_file_name .= $file_id;
+ $rss_save_file_name .= '.rss';
+ return $rss_save_file_name;
+ }
+
+ /**
+ * ¥Õ¥¡¥¤¥ëÄɲÃ
+ *
+ * @param none
+ */
+ function add_file () {
+ $ret = ACSFileInfoModel::insert_file_info($this);
+
+ return $ret;
+ }
+
+ /**
+ * ¥¢¥Ã¥×¥í¡¼¥É¥Õ¥¡¥¤¥ëÊݸ
+ * ¥Æ¥ó¥Ý¥é¥ê¥Õ¥¡¥¤¥ë¤ò¥Õ¥©¥ë¥À¤Î³ÊǼ¾ì½ê¤Ø°ÜÆ°¤¹¤ë
+ *
+ * @param $save_mode Êݸ¤¹¤ë¥â¡¼¥É ('PROFILE' or 'DIARY' or 'BBS' or 'FOLDER')
+ */
+ function save_upload_file ($save_mode) {
+ // 0¥Ð¥¤¥È¥Õ¥¡¥¤¥ë¤Î¾ì¹ç¤Ï¡¢¥¨¥é¡¼
+ if ($this->get_file_size() <= 0) {
+ return false;
+ }
+
+ /* ¥Ç¥£¥ì¥¯¥È¥ê¸ºß¥Á¥§¥Ã¥¯ */
+ // ¤Ê¤¤¾ì¹ç¤ÏºîÀ®¤¹¤ë
+ $to_dir = ACS_FOLDER_DIR . "/";
+ $to_dir .= $this->get_upload_file_save_path($this->get_owner_community_id());
+ if(!file_exists($to_dir)) {mkdir($to_dir); chmod($to_dir, 0777);}
+
+ $from = $this->get_upload_temp_file_name();
+ $to = ACS_FOLDER_DIR . "/" . $this->get_server_file_name();
+ if(is_uploaded_file($from)){
+ $ret = move_uploaded_file($from, $to);
+ if (!$ret) {
+ return $ret;
+ }
+ }else{
+ //ľÀܤΥ¢¥Ã¥×¥í¡¼¥É¥Õ¥¡¥¤¥ë¤Ç¤Ï¤Ê¤¤¾ì¹ç¡¢°ÜÆ°¤¹¤ë
+ $ret = rename($from, $to);
+ }
+ /* ²èÁü¤Î¾ì¹ç¡¢¥µ¥à¥Í¥¤¥ë¤òºîÀ® */
+ if ($this->is_image_file()) {
+ $ret = $this->make_thumbnail($to, $save_mode);
+ }
+ return $ret;
+ }
+
+ /**
+ * ¥µ¥à¥Í¥¤¥ë²èÁüºîÀ®
+ *
+ * @param $target_file ¥µ¥à¥Í¥¤¥ëºîÀ®¸µ ²èÁü¥Õ¥¡¥¤¥ë¥Ñ¥¹
+ * @param $save_mode Êݸ¤¹¤ë¥â¡¼¥É ('PROFILE' or 'DIARY' or 'BBS' or 'FOLDER')
+ */
+ function make_thumbnail ($target_file, $save_mode) {
+ // ¥·¥¹¥Æ¥àÀßÄꥰ¥ë¡¼¥×̾
+ //$system_config_group = '²èÁü¥Õ¥¡¥¤¥ë';
+ $system_config_group = ACSMsg::get_mst('system_config_group','D04');
+
+ // ²èÁü¥µ¥¤¥º¤ò¼èÆÀ
+ $default_width_max = "";
+ $default_height_max = "";
+ $thumb_width_max = "";
+ $thumb_height_max = "";
+ $rss_width_max = "";
+ $rss_height_max = "";
+
+ switch ($save_mode) {
+ case 'PROFILE':
+ $default_width_max = ACSSystemConfig::get_keyword_value($system_config_group, 'PROFILE_IMAGE_WIDTH_MAX');
+ $default_height_max = ACSSystemConfig::get_keyword_value($system_config_group, 'PROFILE_IMAGE_HEIGHT_MAX');
+ $thumb_width_max = ACSSystemConfig::get_keyword_value($system_config_group, 'PROFILE_IMAGE_THUMB_WIDTH_MAX');
+ $thumb_height_max = ACSSystemConfig::get_keyword_value($system_config_group, 'PROFILE_IMAGE_THUMB_HEIGHT_MAX');
+ break;
+
+ case 'DIARY':
+ $default_width_max = ACSSystemConfig::get_keyword_value($system_config_group, 'DIARY_IMAGE_WIDTH_MAX');
+ $default_height_max = ACSSystemConfig::get_keyword_value($system_config_group, 'DIARY_IMAGE_HEIGHT_MAX');
+ $thumb_width_max = ACSSystemConfig::get_keyword_value($system_config_group, 'DIARY_IMAGE_THUMB_WIDTH_MAX');
+ $thumb_height_max = ACSSystemConfig::get_keyword_value($system_config_group, 'DIARY_IMAGE_THUMB_HEIGHT_MAX');
+ break;
+
+ case 'BBS':
+ $default_width_max = ACSSystemConfig::get_keyword_value($system_config_group, 'BBS_IMAGE_WIDTH_MAX');
+ $default_height_max = ACSSystemConfig::get_keyword_value($system_config_group, 'BBS_IMAGE_HEIGHT_MAX');
+ $thumb_width_max = ACSSystemConfig::get_keyword_value($system_config_group, 'BBS_IMAGE_THUMB_WIDTH_MAX');
+ $thumb_height_max = ACSSystemConfig::get_keyword_value($system_config_group, 'BBS_IMAGE_THUMB_HEIGHT_MAX');
+ $rss_width_max = ACSSystemConfig::get_keyword_value($system_config_group, 'BBS_IMAGE_RSS_WIDTH_MAX');
+ $rss_height_max = ACSSystemConfig::get_keyword_value($system_config_group, 'BBS_IMAGE_RSS_HEIGHT_MAX');
+ break;
+
+ case 'FOLDER':
+ $thumb_width_max = ACSSystemConfig::get_keyword_value($system_config_group, 'FOLDER_IMAGE_THUMB_WIDTH_MAX');
+ $thumb_height_max = ACSSystemConfig::get_keyword_value($system_config_group, 'FOLDER_IMAGE_THUMB_HEIGHT_MAX');
+ break;
+
+ default:
+ return false;
+ }
+
+ // ¥µ¥à¥Í¥¤¥ë²èÁüºîÀ®
+ // ImageMagick
+ $image_obj = new ACSImageMagickWrapper($target_file);
+ if (!$image_obj) {
+ return false;
+ }
+
+ // ºÇÂ祵¥¤¥º¤è¤êÂ礤¤¾ì¹ç¤Ï½Ì¾®¤¹¤ë
+ // ¥Õ¥©¥ë¥À¤Î¾ì¹ç¤ÏÀ©¸Â¤Ê¤·
+ if ($save_mode != 'FOLDER') {
+ $new_image_name = $image_obj->reduce_image($default_width_max, $default_height_max);
+ }
+
+ // ¥µ¥à¥Í¥¤¥ëºîÀ®
+ $new_thumb_name = $image_obj->make_jpg_thumbnail(ACS_FOLDER_DIR . $this->get_thumbnail_server_file_name(),
+ $thumb_width_max, $thumb_height_max);
+
+ // RSS ¥Õ¥£¡¼¥ÉÍÑ
+ // BBS ¤Î¾ì¹ç¤Ï¡¢RSSÍÑ¥Õ¥¡¥¤¥ë¤òºîÀ®
+ if ($save_mode == 'BBS') {
+ $rss_server_file_name = $this->get_rss_save_file_name($this->get_owner_community_id(), $this->get_file_id());
+ $new_thumb_name = $image_obj->make_jpg_thumbnail(ACS_FOLDER_DIR . $rss_server_file_name,
+ $rss_width_max, $rss_height_max);
+ $this->set_rss_server_file_name($rss_server_file_name);
+ }
+
+ return true;
+ }
+
+ /**
+ * ¥Õ¥¡¥¤¥ë¥À¥¦¥ó¥í¡¼¥É
+ *
+ * @param none
+ *
+ * @return none
+ */
+ function download_file ($mode = '') {
+ // ¥Õ¥¡¥¤¥ë¥Ñ¥¹
+ if ($mode == 'thumb') {
+ $file_path = $this->get_thumbnail_server_file_name();
+ } else if ($mode == 'rss') {
+ $file_path = $this->get_rss_server_file_name();
+ } else {
+ $file_path = $this->get_server_file_name();
+ }
+
+ // ¥Õ¥¡¥¤¥ë¤¬Æɤ߹þ¤ß¤Ç¤¤Ê¤¤¾ì¹ç
+ if (!is_readable(ACS_FOLDER_DIR . $file_path)) {
+ header("Cache-Control: public, max-age=0");
+ header("Pragma:");
+ echo "Not Found";
+ return;
+ }
+
+ // ¥À¥¦¥ó¥í¡¼¥É¥Õ¥¡¥¤¥ë̾
+ //$download_file_name = mb_convert_encoding($this->get_display_file_name(), mb_http_output());
+ $download_file_name = $this->get_display_file_name();
+
+ // Content-type
+ $content_type = $this->get_mime_type();
+ if ($content_type == '') {
+ $content_type = 'application/octet-stream';
+ }
+
+ // charset (text¤Î¾ì¹ç)
+ if (preg_match('/text/', $content_type)) {
+ $str = implode('', file(ACS_FOLDER_DIR . $file_path));
+ $encoding = mb_detect_encoding($str, 'auto');
+ if ($encoding == 'ASCII' && mb_http_output() != 'pass') {
+ $content_type .= "; charset=" . mb_preferred_mime_name(mb_http_output());
+ } else {
+ $content_type .= "; charset=" . mb_preferred_mime_name($encoding);
+
+ }
+ }
+
+ // action: inline(¥Ö¥é¥¦¥¶Æâɽ¼¨), attachment(¥À¥¦¥ó¥í¡¼¥É¥À¥¤¥¢¥í¥°)
+ //if (preg_match('/text|image/', $content_type)) {
+ if ($this->is_image_file() or $this->is_text_file()) {
+ $action = 'inline';
+ } else {
+ $action = 'attachment';
+ }
+
+ // output_buffering¤ò̵¸ú¤Ë¤¹¤ë
+ mb_http_output('pass');
+ if ($mode == 'thumb') {
+ header("Cache-Control: public, max-age=1800");
+ header("Pragma:");
+/*
+header("Pragma: no-cache");
+header("Cache-Control: no-store");
+header("Cache-Control: no-cache");
+header("Expires: -1");
+//header("Expires: 0");
+*/
+ } else {
+ header("Cache-Control: public, max-age=0");
+ header("Pragma:");
+/*
+//header("Pragma: no-store");
+header("Pragma: no-cache");
+header("Cache-Control: no-store");
+header("Cache-Control: no-cache");
+//header("Expires: 0");
+header("Expires: -1");
+*/
+ }
+
+ // HTTP¥Ø¥Ã¥À¤òÅǤ¯ (action: inline, attachment)
+ if ($this->is_image_file()) {
+ header("Content-type: $content_type");
+ header("Content-disposition: $action; filename=\"$download_file_name\"");
+ } else {
+ header("Content-type: $content_type");
+ header("Content-disposition: $action; attachment; filename=\"" . ACSFile::get_download_name( $download_file_name ) . '"' );
+
+ }
+
+ // ¥Õ¥¡¥¤¥ë¤òÆɤ߽Ф¹
+ readfile(ACS_FOLDER_DIR . $file_path);
+ }
+
+ /**
+ * ÍúÎò¥Õ¥¡¥¤¥ë¥À¥¦¥ó¥í¡¼¥É
+ *
+ * @param none
+ *
+ * @return none
+ */
+ function download_history_file($file_history_id, $mode = '') {
+ $file_history_row = ACSFileHistory::get_file_history_row($file_history_id);
+
+ // ¥Õ¥¡¥¤¥ë¥Ñ¥¹
+ if ($mode == 'thumb') {
+ $file_path = $file_history_row['thumbnail_server_file_name'];
+ } else {
+ $file_path = $file_history_row['server_file_name'];
+ }
+
+ // ¥Õ¥¡¥¤¥ë¤¬Æɤ߹þ¤ß¤Ç¤¤Ê¤¤¾ì¹ç
+ if (!is_readable(ACS_FOLDER_DIR . $file_path)) {
+ header("Cache-Control: public, max-age=0");
+ header("Pragma:");
+ echo "Not Found";
+ return;
+ }
+
+ // ¥À¥¦¥ó¥í¡¼¥É¥Õ¥¡¥¤¥ë̾
+// $download_file_name = mb_convert_encoding($this->get_display_file_name(), mb_http_output());
+ $download_file_name = $this->get_display_file_name();
+
+ // Content-type
+ $content_type = $file_history_row['mime_type'];
+ if ($content_type == '') {
+ $content_type = 'application/octet-stream';
+ }
+
+ // charset (text¤Î¾ì¹ç)
+ if (preg_match('/text/', $content_type)) {
+ $str = implode('', file(ACS_FOLDER_DIR . $file_path));
+ $encoding = mb_detect_encoding($str, 'auto');
+ if ($encoding == 'ASCII' && mb_http_output() != 'pass') {
+ $content_type .= "; charset=" . mb_preferred_mime_name(mb_http_output());
+ } else {
+ $content_type .= "; charset=" . mb_preferred_mime_name($encoding);
+ }
+ }
+
+ // action: inline(¥Ö¥é¥¦¥¶Æâɽ¼¨), attachment(¥À¥¦¥ó¥í¡¼¥É¥À¥¤¥¢¥í¥°)
+ //if (preg_match('/text|image/', $content_type)) {
+ if (preg_match('/image/', $file_history_row['mime_type']) || preg_match('/text/', $file_history_row['mime_type'])) {
+ $action = 'inline';
+ } else {
+ $action = 'attachment';
+ }
+
+ // HTTP¥Ø¥Ã¥À¤òÅǤ¯ (action: inline, attachment)
+// header("Content-disposition: $action; filename=\"$download_file_name\"");
+ header("Content-disposition: $action; attachment; filename=\"" . ACSFile::get_download_name( $download_file_name ) . '"' );
+ header("Content-type: $content_type");
+
+ // output_buffering¤ò̵¸ú¤Ë¤¹¤ë
+ mb_http_output('pass');
+ if ($mode == 'thumb') {
+ header("Cache-Control: public, max-age=1800");
+ header("Pragma:");
+ } else {
+ header("Cache-Control: public, max-age=0");
+ header("Pragma:");
+ }
+
+ // ¥Õ¥¡¥¤¥ë¤òÆɤ߽Ф¹
+ readfile(ACS_FOLDER_DIR . $file_path);
+ }
+
+ /**
+ * ²èÁü¥Õ¥¡¥¤¥ëɽ¼¨
+ *
+ * @param $mode :NULL, thumb, rss
+ *
+ * @return true/false
+ */
+ function view_image ($mode) {
+ $mime_type = $this->get_mime_type();
+
+ if ($this->is_image_file()) {
+ // image ¥Õ¥¡¥¤¥ë½ÐÎÏ
+ $this->download_file($mode);
+ return true;
+
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * ²èÁü¥Õ¥¡¥¤¥ë¤«¤É¤¦¤«
+ */
+ function is_image_file () {
+ if (preg_match('/image/', $this->get_mime_type())) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * ¥Æ¥¥¹¥È¥Õ¥¡¥¤¥ë¤«¤É¤¦¤«
+ */
+ function is_text_file () {
+ if (preg_match('/text/', $this->get_mime_type())) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * ɽ¼¨ÍÑ¥Õ¥¡¥¤¥ë̾Êѹ¹
+ *
+ * @param $new_display_file_name
+ * @return $ret
+ */
+ function rename_display_file_name ($new_display_file_name) {
+ $ret = ACSFileInfoModel::update_display_file_name($this->get_file_id(), $new_display_file_name);
+ return $ret;
+ }
+
+ /**
+ * ¥Õ¥¡¥¤¥ëºï½ü
+ *
+ * @return $ret
+ */
+ function delete_file () {
+ $ret = ACSFileInfoModel::delete_file_info($this);
+ return $ret;
+ }
+
+ /**
+ * ¥Õ¥¡¥¤¥ë¤Î¥¢¥¯¥»¥¹ÍúÎò¾ðÊó¤ò¼èÆÀ¤¹¤ë
+ *
+ * @param $user_community_id ¥æ¡¼¥¶¥³¥ß¥å¥Ë¥Æ¥£ID
+ * @param $file_id ¥Õ¥¡¥¤¥ëID
+ * @return ¥Õ¥¡¥¤¥ë¤Î¥¢¥¯¥»¥¹ÍúÎò¾ðÊó (Ï¢ÁÛÇÛÎó)
+ */
+ static function get_file_access_history_row($user_community_id, $file_id) {
+ $user_community_id = pg_escape_string($user_community_id);
+ $file_id = pg_escape_string($file_id);
+
+ $sql = "SELECT *" .
+ " FROM file_access_history" .
+ " WHERE user_community_id = '" . $user_community_id . "'" .
+ " AND file_id = '" . $file_id . "'";
+
+ $row = ACSDB::_get_row($sql);
+ return $row;
+ }
+
+ /**
+ * ¥Õ¥¡¥¤¥ë¤Î¥¢¥¯¥»¥¹ÍúÎò¤òÅÐÏ¿¤¹¤ë
+ *
+ * @param $file_id
+ * @return À®¸ù(true) / ¼ºÇÔ(false)
+ */
+ static function set_file_access_history($user_community_id, $file_id) {
+ // ¥Õ¥¡¥¤¥ë¥¢¥¯¥»¥¹ÍúÎò
+ $file_access_history_row = ACSFile::get_file_access_history_row($user_community_id, $file_id);
+
+ $file_access_history_form = array(
+ 'user_community_id' => $user_community_id,
+ 'file_id' => $file_id,
+ 'access_date' => 'now'
+ );
+
+ // ¥ì¥³¡¼¥É¤¬Â¸ºß¤¹¤ë¾ì¹ç¤ÏUPDATE
+ if ($file_access_history_row) {
+ ACSFileAccessHistoryModel::update_file_access_history($file_access_history_form);
+ // ¥ì¥³¡¼¥É¤¬Â¸ºß¤·¤Ê¤¤¾ì¹ç¤ÏINSERT
+ } else {
+ ACSFileAccessHistoryModel::insert_file_access_history($file_access_history_form);
+ }
+ }
+
+ /**
+ * ¥Õ¥¡¥¤¥ë¥À¥¦¥ó¥í¡¼¥Éµ¡Ç½ÍÑ¡§¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°¤òÀßÄꤹ¤ë
+ *
+ * @return À®¸ù(true) / ¼ºÇÔ(false)
+ */
+ function get_current_mb_encoding() {
+ // ¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°¤ò¸ÇÄꤹ¤ë¾ì¹ç
+ return ACSFile::_get_mb_encoding( 'EUC-JP' ) ;
+ //return ACSFile::_get_mb_encoding( lang_get( 'charset' ) );
+ }
+
+ /**
+ * ¥Õ¥¡¥¤¥ë¥À¥¦¥ó¥í¡¼¥Éµ¡Ç½ÍÑ¡§¥¨¥ó¥³¡¼¥É¤ò¹Ô¤¦
+ *
+ * @return À®¸ù(¥¨¥ó¥³¡¼¥É¸å) / ¼ºÇÔ(null)
+ */
+ function _get_mb_encoding( $p_charset ) {
+
+ $mb_encoding_array = array(
+ 'Shift_JIS' => 'SJIS-win',
+ 'EUC-JP' => 'EUC-JP',
+ 'UTF-8' => 'UTF-8'
+ );
+
+ if ( isset( $mb_encoding_array[$p_charset] ) ) {
+ return $mb_encoding_array[$p_charset];
+ }
+
+ return null;
+ }
+
+ /**
+ * ¥Õ¥¡¥¤¥ë¥À¥¦¥ó¥í¡¼¥Éµ¡Ç½ÍÑ¡§¥À¥¦¥ó¥í¡¼¥É¥Õ¥¡¥¤¥ë̾¤ò¼èÆÀ¤¹¤ë
+ *
+ * @return ¥Õ¥¡¥¤¥ë̾
+ */
+ function get_download_name( $p_filename ) {
+
+ $encoding = ACSFile::get_current_mb_encoding();
+ if ( $encoding === null ) {
+ return $p_filename;
+ }
+
+ $ua = $_SERVER['HTTP_USER_AGENT'];
+
+ // ¥æ¡¼¥¶¡¼¥¨¡¼¥¸¥§¥ó¥È¤Ë¤è¤Ã¤Æ¥Õ¥¡¥¤¥ë̾¤òÊÑ´¹
+ if ( strstr( $ua, 'MSIE' ) && !strstr( $ua, 'Opera' ) ) {
+ $t_filename = mb_convert_encoding( $p_filename, 'SJIS-win', $encoding );
+
+ } elseif (strstr( $ua, 'Safari') ) {
+ // SafariÂбþ
+ $t_filename = "";
+
+ } else {
+ $t_filename = mb_convert_encoding( $p_filename, 'UTF-8', $encoding );
+ }
+
+ return $t_filename;
+ }
+
+}
+?>