Skip to content

Commit

Permalink
merge -c2785 from branch 2.0 to trunk
Browse files Browse the repository at this point in the history
bug 897 fixed: controls added in pwg.images.add to have clear error messages
if permission is denied or any error occur during file write.


git-svn-id: http://piwigo.org/svn/trunk@2786 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
plegall committed Oct 20, 2008
1 parent d3f7c13 commit 463c101
Showing 1 changed file with 57 additions and 6 deletions.
63 changes: 57 additions & 6 deletions include/ws_functions.inc.php
Expand Up @@ -934,7 +934,21 @@ function ws_images_add($params, &$service)
if (!is_dir($upload_dir)) {
umask(0000);
$recursive = true;
mkdir($upload_dir, 0777, $recursive);
if (!@mkdir($upload_dir, 0777, $recursive))
{
return new PwgError(500, 'error during directory creation');
}
}

if (!is_writable($upload_dir))
{
// last chance to make the directory writable
@chmod($upload_dir, 0777);

if (!is_writable($upload_dir))
{
return new PwgError(500, 'directory has no write access');
}
}

// compute file path
Expand All @@ -945,7 +959,10 @@ function ws_images_add($params, &$service)

// dump the photo file
$fh_file = fopen($file_path, 'w');
fwrite($fh_file, base64_decode($params['file_content']));
if (!fwrite($fh_file, base64_decode($params['file_content'])))
{
return new PwgError(500, 'error while writing file');
}
fclose($fh_file);
chmod($file_path, 0644);

Expand All @@ -960,7 +977,21 @@ function ws_images_add($params, &$service)
$thumbnail_dir = $upload_dir.'/thumbnail';
if (!is_dir($thumbnail_dir)) {
umask(0000);
mkdir($thumbnail_dir, 0777);
if (!@mkdir($thumbnail_dir, 0777))
{
return new PwgError(500, 'error during thumbnail directory creation');
}
}

if (!is_writable($thumbnail_dir))
{
// last chance to make the directory writable
@chmod($thumbnail_dir, 0777);

if (!is_writable($thumbnail_dir))
{
return new PwgError(500, 'thumbnail directory has no write access');
}
}

// thumbnail path, the filename may use a prefix and the extension is
Expand All @@ -975,7 +1006,10 @@ function ws_images_add($params, &$service)

// dump the thumbnail
$fh_thumbnail = fopen($thumbnail_path, 'w');
fwrite($fh_thumbnail, base64_decode($params['thumbnail_content']));
if (!fwrite($fh_thumbnail, base64_decode($params['thumbnail_content'])))
{
return new PwgError(500, 'error while writing thumbnail');
}
fclose($fh_thumbnail);
chmod($thumbnail_path, 0644);

Expand All @@ -993,9 +1027,23 @@ function ws_images_add($params, &$service)
$high_dir = $upload_dir.'/pwg_high';
if (!is_dir($high_dir)) {
umask(0000);
mkdir($high_dir, 0777);
if (!@mkdir($high_dir, 0777))
{
return new PwgError(500, 'error during high directory creation');
}
}

if (!is_writable($high_dir))
{
// last chance to make the directory writable
@chmod($high_dir, 0777);

if (!is_writable($high_dir))
{
return new PwgError(500, 'high directory has no write access');
}
}

// high resolution path, same name as web size file
$high_path = sprintf(
'%s/%s.%s',
Expand All @@ -1006,7 +1054,10 @@ function ws_images_add($params, &$service)

// dump the high resolution file
$fh_high = fopen($high_path, 'w');
fwrite($fh_high, base64_decode($params['high_content']));
if (!fwrite($fh_high, base64_decode($params['high_content'])))
{
return new PwgError(500, 'error while writing high');
}
fclose($fh_high);
chmod($high_path, 0644);

Expand Down

0 comments on commit 463c101

Please sign in to comment.