feature 2531 added: pwg.images.add is able to generate web size + thumbnail
(remote client needs to set "resize" option to something else than 0). When the "resize" is On, only the "file" must be send with pwg.images.addChunk. git-svn-id: http://piwigo.org/svn/branches/2.3@12722 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
parent
6e6410e248
commit
094bb7e682
2 changed files with 118 additions and 69 deletions
|
@ -1654,80 +1654,132 @@ SELECT
|
||||||
return new PwgError(500, 'file already exists');
|
return new PwgError(500, 'file already exists');
|
||||||
}
|
}
|
||||||
|
|
||||||
// current date
|
if ($params['resize'])
|
||||||
list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
|
|
||||||
list($year, $month, $day) = preg_split('/[^\d]/', $dbnow, 4);
|
|
||||||
|
|
||||||
// upload directory hierarchy
|
|
||||||
$upload_dir = sprintf(
|
|
||||||
$conf['upload_dir'].'/%s/%s/%s',
|
|
||||||
$year,
|
|
||||||
$month,
|
|
||||||
$day
|
|
||||||
);
|
|
||||||
|
|
||||||
// compute file path
|
|
||||||
$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';
|
|
||||||
|
|
||||||
// add files
|
|
||||||
$file_infos = add_file($file_path, 'file', $params['original_sum'], $params['file_sum']);
|
|
||||||
$thumb_infos = add_file($file_path, 'thumb', $params['original_sum'], $params['thumbnail_sum']);
|
|
||||||
|
|
||||||
if (isset($params['high_sum']))
|
|
||||||
{
|
{
|
||||||
$high_infos = add_file($file_path, 'high', $params['original_sum'], $params['high_sum']);
|
ws_logfile('[pwg.images.add] resize activated');
|
||||||
}
|
|
||||||
|
// temporary file path
|
||||||
|
$type = 'file';
|
||||||
|
$file_path = $conf['upload_dir'].'/buffer/'.$params['original_sum'].'-'.$type;
|
||||||
|
|
||||||
|
merge_chunks($file_path, $params['original_sum'], $type);
|
||||||
|
chmod($file_path, 0644);
|
||||||
|
|
||||||
|
$image_id = add_uploaded_file(
|
||||||
|
$file_path,
|
||||||
|
$params['original_filename']
|
||||||
|
);
|
||||||
|
|
||||||
// database registration
|
// add_uploaded_file doesn't remove the original file in the buffer
|
||||||
$insert = array(
|
// directory if it was not uploaded as $_FILES
|
||||||
'file' => !empty($params['original_filename']) ? $params['original_filename'] : $filename_wo_ext.'.jpg',
|
unlink($file_path);
|
||||||
'date_available' => $dbnow,
|
|
||||||
'tn_ext' => 'jpg',
|
$info_columns = array(
|
||||||
'name' => $params['name'],
|
'name',
|
||||||
'path' => $file_path,
|
'author',
|
||||||
'filesize' => $file_infos['filesize'],
|
'comment',
|
||||||
'width' => $file_infos['width'],
|
'level',
|
||||||
'height' => $file_infos['height'],
|
'date_creation',
|
||||||
'md5sum' => $params['original_sum'],
|
|
||||||
'added_by' => $user['id'],
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$info_columns = array(
|
foreach ($info_columns as $key)
|
||||||
'name',
|
|
||||||
'author',
|
|
||||||
'comment',
|
|
||||||
'level',
|
|
||||||
'date_creation',
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach ($info_columns as $key)
|
|
||||||
{
|
|
||||||
if (isset($params[$key]))
|
|
||||||
{
|
{
|
||||||
$insert[$key] = $params[$key];
|
if (isset($params[$key]))
|
||||||
|
{
|
||||||
|
$update[$key] = $params[$key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count(array_keys($update)) > 0)
|
||||||
|
{
|
||||||
|
single_update(
|
||||||
|
IMAGES_TABLE,
|
||||||
|
$update,
|
||||||
|
array('id' => $image_id)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
if (isset($params['high_sum']))
|
|
||||||
{
|
{
|
||||||
$insert['has_high'] = 'true';
|
// current date
|
||||||
$insert['high_filesize'] = $high_infos['filesize'];
|
list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
|
||||||
$insert['high_width'] = $high_infos['width'];
|
list($year, $month, $day) = preg_split('/[^\d]/', $dbnow, 4);
|
||||||
$insert['high_height'] = $high_infos['height'];
|
|
||||||
|
// upload directory hierarchy
|
||||||
|
$upload_dir = sprintf(
|
||||||
|
$conf['upload_dir'].'/%s/%s/%s',
|
||||||
|
$year,
|
||||||
|
$month,
|
||||||
|
$day
|
||||||
|
);
|
||||||
|
|
||||||
|
// compute file path
|
||||||
|
$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';
|
||||||
|
|
||||||
|
// add files
|
||||||
|
$file_infos = add_file($file_path, 'file', $params['original_sum'], $params['file_sum']);
|
||||||
|
$thumb_infos = add_file($file_path, 'thumb', $params['original_sum'], $params['thumbnail_sum']);
|
||||||
|
|
||||||
|
if (isset($params['high_sum']))
|
||||||
|
{
|
||||||
|
$high_infos = add_file($file_path, 'high', $params['original_sum'], $params['high_sum']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// database registration
|
||||||
|
$insert = array(
|
||||||
|
'file' => !empty($params['original_filename']) ? $params['original_filename'] : $filename_wo_ext.'.jpg',
|
||||||
|
'date_available' => $dbnow,
|
||||||
|
'tn_ext' => 'jpg',
|
||||||
|
'name' => $params['name'],
|
||||||
|
'path' => $file_path,
|
||||||
|
'filesize' => $file_infos['filesize'],
|
||||||
|
'width' => $file_infos['width'],
|
||||||
|
'height' => $file_infos['height'],
|
||||||
|
'md5sum' => $params['original_sum'],
|
||||||
|
'added_by' => $user['id'],
|
||||||
|
);
|
||||||
|
|
||||||
|
$info_columns = array(
|
||||||
|
'name',
|
||||||
|
'author',
|
||||||
|
'comment',
|
||||||
|
'level',
|
||||||
|
'date_creation',
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($info_columns as $key)
|
||||||
|
{
|
||||||
|
if (isset($params[$key]))
|
||||||
|
{
|
||||||
|
$insert[$key] = $params[$key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($params['high_sum']))
|
||||||
|
{
|
||||||
|
$insert['has_high'] = 'true';
|
||||||
|
$insert['high_filesize'] = $high_infos['filesize'];
|
||||||
|
$insert['high_width'] = $high_infos['width'];
|
||||||
|
$insert['high_height'] = $high_infos['height'];
|
||||||
|
}
|
||||||
|
|
||||||
|
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
||||||
|
mass_inserts(
|
||||||
|
IMAGES_TABLE,
|
||||||
|
array_keys($insert),
|
||||||
|
array($insert)
|
||||||
|
);
|
||||||
|
|
||||||
|
$image_id = pwg_db_insert_id(IMAGES_TABLE);
|
||||||
|
|
||||||
|
// update metadata from the uploaded file (exif/iptc)
|
||||||
|
require_once(PHPWG_ROOT_PATH.'admin/include/functions_metadata.php');
|
||||||
|
update_metadata(array($image_id=>$file_path));
|
||||||
}
|
}
|
||||||
|
|
||||||
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
|
||||||
mass_inserts(
|
|
||||||
IMAGES_TABLE,
|
|
||||||
array_keys($insert),
|
|
||||||
array($insert)
|
|
||||||
);
|
|
||||||
|
|
||||||
$image_id = pwg_db_insert_id(IMAGES_TABLE);
|
|
||||||
|
|
||||||
// let's add links between the image and the categories
|
// let's add links between the image and the categories
|
||||||
if (isset($params['categories']))
|
if (isset($params['categories']))
|
||||||
{
|
{
|
||||||
|
@ -1743,10 +1795,6 @@ SELECT
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// update metadata from the uploaded file (exif/iptc)
|
|
||||||
require_once(PHPWG_ROOT_PATH.'admin/include/functions_metadata.php');
|
|
||||||
update_metadata(array($image_id=>$file_path));
|
|
||||||
|
|
||||||
invalidate_user_cache();
|
invalidate_user_cache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
3
ws.php
3
ws.php
|
@ -226,7 +226,7 @@ function ws_addDefaultMethods( $arr )
|
||||||
'ws_images_add',
|
'ws_images_add',
|
||||||
array(
|
array(
|
||||||
'file_sum' => array(),
|
'file_sum' => array(),
|
||||||
'thumbnail_sum' => array(),
|
'thumbnail_sum' => array('default' => null),
|
||||||
'high_sum' => array('default' => null),
|
'high_sum' => array('default' => null),
|
||||||
'original_sum' => array(),
|
'original_sum' => array(),
|
||||||
'original_filename' => array('default' => null),
|
'original_filename' => array('default' => null),
|
||||||
|
@ -240,6 +240,7 @@ function ws_addDefaultMethods( $arr )
|
||||||
'default' => 0,
|
'default' => 0,
|
||||||
'maxValue' => $conf['available_permission_levels']
|
'maxValue' => $conf['available_permission_levels']
|
||||||
),
|
),
|
||||||
|
'resize' => array('default' => false),
|
||||||
),
|
),
|
||||||
'POST method only.
|
'POST method only.
|
||||||
<br><b>categories</b> is a string list "category_id[,rank];category_id[,rank]" The rank is optional and is equivalent to "auto" if not given.'
|
<br><b>categories</b> is a string list "category_id[,rank];category_id[,rank]" The rank is optional and is equivalent to "auto" if not given.'
|
||||||
|
|
Loading…
Add table
Reference in a new issue