aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2008-07-30 21:53:00 +0000
committerplegall <plg@piwigo.org>2008-07-30 21:53:00 +0000
commit45960b4631e8d92a3ccd87fa4732dc1f74f1b017 (patch)
treeecbecf51825baa937bb960022d097b510a3ca542 /include
parent4dcec5fb8a2c85a9292374672b887b46f2862a53 (diff)
feature 839, first step : early proof of concept, no error handling. A
remote client can add a photo in a category thanks to the web API. A new "upload" directory is created (write access required on the base directory). Uploaded photo have path such as upload/<year>/<month>/<day>/<datetime>-random.jpg. The thumbnail must come with the "web sized" photo. The photo has no storage_category_id. Bugs still need to be fixed and a discussion must occur before next steps. git-svn-id: http://piwigo.org/svn/trunk@2463 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-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)
*/