Changeset 3192 for branches/2.0/include
- Timestamp:
- Mar 13, 2009, 12:09:22 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.0/include/ws_functions.inc.php
r3147 r3192 880 880 } 881 881 882 function ws_images_add_chunk($params, &$service) 883 { 884 // data 885 // original_sum 886 // type {thumb, file, high} 887 // position 888 889 if (!is_admin() || is_adviser() ) 890 { 891 return new PwgError(401, 'Access denied'); 892 } 893 894 $upload_dir = PHPWG_ROOT_PATH.'upload/buffer'; 895 896 // create the upload directory tree if not exists 897 if (!is_dir($upload_dir)) { 898 umask(0000); 899 $recursive = true; 900 if (!@mkdir($upload_dir, 0777, $recursive)) 901 { 902 return new PwgError(500, 'error during buffer directory creation'); 903 } 904 } 905 906 if (!is_writable($upload_dir)) 907 { 908 // last chance to make the directory writable 909 @chmod($upload_dir, 0777); 910 911 if (!is_writable($upload_dir)) 912 { 913 return new PwgError(500, 'buffer directory has no write access'); 914 } 915 } 916 917 secure_directory($upload_dir); 918 919 $filename = sprintf( 920 '%s-%s-%05u.block', 921 $params['original_sum'], 922 $params['type'], 923 $params['position'] 924 ); 925 926 $bytes_written = file_put_contents( 927 $upload_dir.'/'.$filename, 928 $params['data'] 929 ); 930 931 if (false === $bytes_written) { 932 return new PwgError( 933 500, 934 'an error has occured while writting chunk '.$params['position'].' for '.$params['type'] 935 ); 936 } 937 } 938 939 function merge_chunks($output_filepath, $original_sum, $type) 940 { 941 ws_logfile('[merge_chunks] input parameter $output_filepath : '.$output_filepath); 942 943 $upload_dir = PHPWG_ROOT_PATH.'upload/buffer'; 944 $pattern = '/'.$original_sum.'-'.$type.'/'; 945 $chunks = array(); 946 947 if ($handle = opendir($upload_dir)) 948 { 949 while (false !== ($file = readdir($handle))) 950 { 951 if (preg_match($pattern, $file)) 952 { 953 ws_logfile($file); 954 array_push($chunks, $upload_dir.'/'.$file); 955 } 956 } 957 closedir($handle); 958 } 959 960 sort($chunks); 961 962 $string = null; 963 foreach ($chunks as $chunk) { 964 $string.= file_get_contents($chunk); 965 unlink($chunk); 966 } 967 if (!file_put_contents($output_filepath, base64_decode($string))) 968 { 969 return new PwgError(500, 'error while merging chunks for '.$output_filepath); 970 } 971 972 } 973 882 974 function ws_images_add($params, &$service) 883 975 { … … 957 1049 $file_path = $upload_dir.'/'.$filename_wo_ext.'.jpg'; 958 1050 959 // dump the photo file 960 $fh_file = fopen($file_path, 'w'); 961 if (!fwrite($fh_file, base64_decode($params['file_content']))) 962 { 963 return new PwgError(500, 'error while writing file'); 964 } 965 fclose($fh_file); 1051 // merge the photo file 1052 merge_chunks($file_path, $params['original_sum'], 'file'); 966 1053 chmod($file_path, 0644); 967 1054 … … 1006 1093 ); 1007 1094 1008 // dump the thumbnail 1009 $fh_thumbnail = fopen($thumbnail_path, 'w'); 1010 if (!fwrite($fh_thumbnail, base64_decode($params['thumbnail_content']))) 1011 { 1012 return new PwgError(500, 'error while writing thumbnail'); 1013 } 1014 fclose($fh_thumbnail); 1095 // merge the thumbnail 1096 merge_chunks($thumbnail_path, $params['original_sum'], 'thumb'); 1015 1097 chmod($thumbnail_path, 0644); 1016 1098 … … 1022 1104 1023 1105 // high resolution 1024 if (isset($params['high_ content']))1106 if (isset($params['high_sum'])) 1025 1107 { 1026 1108 // high resolution directory is a subdirectory of the photo file, hard … … 1056 1138 ); 1057 1139 1058 // dump the high resolution file 1059 $fh_high = fopen($high_path, 'w'); 1060 if (!fwrite($fh_high, base64_decode($params['high_content']))) 1061 { 1062 return new PwgError(500, 'error while writing high'); 1063 } 1064 fclose($fh_high); 1140 // merge the high resolution file 1141 merge_chunks($high_path, $params['original_sum'], 'high'); 1065 1142 chmod($high_path, 0644); 1066 1143 … … 1105 1182 } 1106 1183 1107 if (isset($params['high_ content']))1184 if (isset($params['high_sum'])) 1108 1185 { 1109 1186 $insert['has_high'] = 'true'; … … 1647 1724 } 1648 1725 } 1726 1727 function ws_logfile($string) 1728 { 1729 return true; 1730 1731 file_put_contents( 1732 '/tmp/piwigo_ws.log', 1733 '['.date('c').'] '.$string."\n", 1734 FILE_APPEND 1735 ); 1736 } 1649 1737 ?>
Note: See TracChangeset
for help on using the changeset viewer.