Changeset 4346 for trunk/include/ws_functions.inc.php
- Timestamp:
- Nov 23, 2009, 12:57:44 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/ws_functions.inc.php
r4334 r4346 974 974 if (!file_put_contents($output_filepath, $string, FILE_APPEND)) 975 975 { 976 return new PwgError(500, 'error while writting chunks for '.$output_filepath); 976 new PwgError(500, '[merge_chunks] error while writting chunks for '.$output_filepath); 977 exit(); 977 978 } 978 979 … … 981 982 982 983 ws_logfile('[merge_chunks] memory_get_usage after loading chunks: '.memory_get_usage()); 984 } 985 986 /* 987 * The $file_path must be the path of the basic "web sized" photo 988 * The $type value will automatically modify the $file_path to the corresponding file 989 */ 990 function add_file($file_path, $type, $original_sum, $file_sum) 991 { 992 // resolve the $file_path depending on the $type 993 if ('thumb' == $type) { 994 $file_path = get_thumbnail_location( 995 array( 996 'path' => $file_path, 997 'tn_ext' => 'jpg', 998 ) 999 ); 1000 } 1001 1002 if ('high' == $type) { 1003 @include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php'); 1004 $file_path = get_high_location( 1005 array( 1006 'path' => $file_path, 1007 'has_high' => 'true' 1008 ) 1009 ); 1010 } 1011 1012 $upload_dir = dirname($file_path); 1013 1014 if (!is_dir($upload_dir)) { 1015 umask(0000); 1016 $recursive = true; 1017 if (!@mkdir($upload_dir, 0777, $recursive)) 1018 { 1019 new PwgError(500, '[add_file] error during '.$type.' directory creation'); 1020 exit(); 1021 } 1022 } 1023 1024 if (!is_writable($upload_dir)) 1025 { 1026 // last chance to make the directory writable 1027 @chmod($upload_dir, 0777); 1028 1029 if (!is_writable($upload_dir)) 1030 { 1031 new PwgError(500, '[add_file] '.$type.' directory has no write access'); 1032 exit(); 1033 } 1034 } 1035 1036 secure_directory($upload_dir); 1037 1038 // merge the thumbnail 1039 merge_chunks($file_path, $original_sum, $type); 1040 chmod($file_path, 0644); 1041 1042 // check dumped thumbnail md5 1043 $dumped_md5 = md5_file($file_path); 1044 if ($dumped_md5 != $file_sum) { 1045 new PwgError(500, '[add_file] '.$type.' transfer failed'); 1046 exit(); 1047 } 1048 1049 list($width, $height) = getimagesize($file_path); 1050 $filesize = floor(filesize($file_path)/1024); 1051 1052 return array( 1053 'width' => $width, 1054 'height' => $height, 1055 'filesize' => $filesize, 1056 ); 983 1057 } 984 1058 … … 1025 1099 ); 1026 1100 1027 // create the upload directory tree if not exists1028 if (!is_dir($upload_dir)) {1029 umask(0000);1030 $recursive = true;1031 if (!@mkdir($upload_dir, 0777, $recursive))1032 {1033 return new PwgError(500, 'error during directory creation');1034 }1035 }1036 1037 if (!is_writable($upload_dir))1038 {1039 // last chance to make the directory writable1040 @chmod($upload_dir, 0777);1041 1042 if (!is_writable($upload_dir))1043 {1044 return new PwgError(500, 'directory has no write access');1045 }1046 }1047 1048 secure_directory($upload_dir);1049 1050 1101 // compute file path 1051 1102 $date_string = preg_replace('/[^\d]/', '', $dbnow); … … 1054 1105 $file_path = $upload_dir.'/'.$filename_wo_ext.'.jpg'; 1055 1106 1056 // merge the photo file 1057 merge_chunks($file_path, $params['original_sum'], 'file'); 1058 chmod($file_path, 0644); 1059 1060 // check dumped file md5sum against expected md5sum 1061 $dumped_md5 = md5_file($file_path); 1062 if ($dumped_md5 != $params['file_sum']) { 1063 return new PwgError(500, 'file transfer failed'); 1064 } 1065 1066 // thumbnail directory is a subdirectory of the photo file, hard coded 1067 // "thumbnail" 1068 $thumbnail_dir = $upload_dir.'/'.$conf['dir_thumbnail']; 1069 if (!is_dir($thumbnail_dir)) { 1070 umask(0000); 1071 if (!@mkdir($thumbnail_dir, 0777)) 1072 { 1073 return new PwgError(500, 'error during thumbnail directory creation'); 1074 } 1075 } 1076 1077 if (!is_writable($thumbnail_dir)) 1078 { 1079 // last chance to make the directory writable 1080 @chmod($thumbnail_dir, 0777); 1081 1082 if (!is_writable($thumbnail_dir)) 1083 { 1084 return new PwgError(500, 'thumbnail directory has no write access'); 1085 } 1086 } 1087 1088 secure_directory($thumbnail_dir); 1089 1090 // thumbnail path, the filename may use a prefix and the extension is 1091 // always "jpg" (no matter what the real file format is) 1092 $thumbnail_path = sprintf( 1093 '%s/%s%s.%s', 1094 $thumbnail_dir, 1095 $conf['prefix_thumbnail'], 1096 $filename_wo_ext, 1097 'jpg' 1098 ); 1099 1100 // merge the thumbnail 1101 merge_chunks($thumbnail_path, $params['original_sum'], 'thumb'); 1102 chmod($thumbnail_path, 0644); 1103 1104 // check dumped thumbnail md5 1105 $dumped_md5 = md5_file($thumbnail_path); 1106 if ($dumped_md5 != $params['thumbnail_sum']) { 1107 return new PwgError(500, 'thumbnail transfer failed'); 1108 } 1109 1110 // high resolution 1107 // add files 1108 $file_infos = add_file($file_path, 'file', $params['original_sum'], $params['file_sum']); 1109 $thumb_infos = add_file($file_path, 'thumb', $params['original_sum'], $params['thumbnail_sum']); 1110 1111 1111 if (isset($params['high_sum'])) 1112 1112 { 1113 // high resolution directory is a subdirectory of the photo file, hard 1114 // coded "pwg_high" 1115 $high_dir = $upload_dir.'/pwg_high'; 1116 if (!is_dir($high_dir)) { 1117 umask(0000); 1118 if (!@mkdir($high_dir, 0777)) 1119 { 1120 return new PwgError(500, 'error during high directory creation'); 1121 } 1122 } 1123 1124 if (!is_writable($high_dir)) 1125 { 1126 // last chance to make the directory writable 1127 @chmod($high_dir, 0777); 1128 1129 if (!is_writable($high_dir)) 1130 { 1131 return new PwgError(500, 'high directory has no write access'); 1132 } 1133 } 1134 1135 secure_directory($high_dir); 1136 1137 // high resolution path, same name as web size file 1138 $high_path = sprintf( 1139 '%s/%s.%s', 1140 $high_dir, 1141 $filename_wo_ext, 1142 'jpg' 1143 ); 1144 1145 // merge the high resolution file 1146 merge_chunks($high_path, $params['original_sum'], 'high'); 1147 chmod($high_path, 0644); 1148 1149 // check dumped thumbnail md5 1150 $dumped_md5 = md5_file($high_path); 1151 if ($dumped_md5 != $params['high_sum']) { 1152 return new PwgError(500, 'high resolution transfer failed'); 1153 } 1154 1155 $high_filesize = floor(filesize($high_path)/1024); 1156 } 1157 1158 list($width, $height) = getimagesize($file_path); 1113 $high_infos = add_file($file_path, 'high', $params['original_sum'], $params['high_sum']); 1114 } 1159 1115 1160 1116 // database registration … … 1165 1121 'name' => $params['name'], 1166 1122 'path' => $file_path, 1167 'filesize' => floor(filesize($file_path)/1024),1168 'width' => $ width,1169 'height' => $ height,1123 'filesize' => $file_infos['filesize'], 1124 'width' => $file_infos['width'], 1125 'height' => $file_infos['height'], 1170 1126 'md5sum' => $params['original_sum'], 1171 1127 ); … … 1190 1146 { 1191 1147 $insert['has_high'] = 'true'; 1192 $insert['high_filesize'] = $high_ filesize;1148 $insert['high_filesize'] = $high_infos['filesize']; 1193 1149 } 1194 1150
Note: See TracChangeset
for help on using the changeset viewer.