aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/ws_functions.inc.php100
1 files changed, 100 insertions, 0 deletions
diff --git a/include/ws_functions.inc.php b/include/ws_functions.inc.php
index 7e9c8228a..015f3d391 100644
--- a/include/ws_functions.inc.php
+++ b/include/ws_functions.inc.php
@@ -915,6 +915,106 @@ UPDATE '.IMAGES_TABLE.'
return $affected_rows;
}
+function ws_images_add($params, &$service)
+{
+ global $conf;
+
+ // name
+ // category_id
+ // file_content
+ // file_sum
+ // thumbnail_content
+ // thumbnail_sum
+
+ // $fh_log = fopen('/tmp/php.log', 'w');
+ // fwrite($fh_log, time()."\n");
+ // fwrite($fh_log, 'input: '.$params['file_sum']."\n");
+ // fwrite($fh_log, 'input: '.$params['thumbnail_sum']."\n");
+
+ // current date
+ list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
+ list($year, $month, $day) = preg_split('/[^\d]/', $dbnow, 4);
+
+ $upload_dir = sprintf(
+ PHPWG_ROOT_PATH.'upload/%s/%s/%s',
+ $year,
+ $month,
+ $day
+ );
+
+ fwrite($fh_log, $upload_dir."\n");
+
+ if (!is_dir($upload_dir)) {
+ umask(0000);
+ $recursive = true;
+ mkdir($upload_dir, 0777, $recursive);
+ }
+
+ $date_string = preg_replace('/[^\d]/', '', $dbnow);
+ $random_string = substr($params['file_sum'], 0, 8);
+
+ $filename_wo_ext = $date_string.'-'.$random_string;
+
+ $file_path = $upload_dir.'/'.$filename_wo_ext.'.jpg';
+ $fh_file = fopen($file_path, 'w');
+ fwrite($fh_file, base64_decode($params['file_content']));
+ fclose($fh_file);
+
+ // check dumped file md5sum with expected md5sum
+
+ $thumbnail_dir = $upload_dir.'/thumbnail';
+ if (!is_dir($thumbnail_dir)) {
+ umask(0000);
+ mkdir($thumbnail_dir, 0777);
+ }
+
+ $thumbnail_path = sprintf(
+ '%s/%s%s.%s',
+ $thumbnail_dir,
+ $conf['prefix_thumbnail'],
+ $filename_wo_ext,
+ 'jpg'
+ );
+ $fh_thumbnail = fopen($thumbnail_path, 'w');
+ fwrite($fh_thumbnail, base64_decode($params['thumbnail_content']));
+ fclose($fh_thumbnail);
+
+ // check dumped thumbnail md5
+
+ // fwrite($fh_log, 'output: '.md5_file($file_path)."\n");
+ // fwrite($fh_log, 'output: '.md5_file($thumbnail_path)."\n");
+
+ // database registration
+ $insert = array(
+ 'file' => $filename_wo_ext.'.jpg',
+ 'date_available' => $dbnow,
+ 'tn_ext' => 'jpg',
+ 'name' => $params['name'],
+ 'path' => $file_path,
+ );
+
+ include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
+ mass_inserts(
+ IMAGES_TABLE,
+ array_keys($insert),
+ array($insert)
+ );
+
+ $image_id = mysql_insert_id();
+
+ $insert = array(
+ 'category_id' => $params['category_id'],
+ 'image_id'=> $image_id,
+ );
+ mass_inserts(
+ IMAGE_CATEGORY_TABLE,
+ array_keys($insert),
+ array($insert)
+ );
+
+ // fclose($fh_log);
+}
+
/**
* perform a login (web service method)
*/