diff options
author | plegall <plg@piwigo.org> | 2008-10-20 21:06:21 +0000 |
---|---|---|
committer | plegall <plg@piwigo.org> | 2008-10-20 21:06:21 +0000 |
commit | 463c101a284671eed62108fb90b08398fdd6a93d (patch) | |
tree | b88723ffa27516986ca7e093e5c70d6abd8a1f88 /include | |
parent | d3f7c13587a3c3d584db6f55b500b42a62831af9 (diff) |
merge -c2785 from branch 2.0 to trunk
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
Diffstat (limited to '')
-rw-r--r-- | include/ws_functions.inc.php | 63 |
1 files changed, 57 insertions, 6 deletions
diff --git a/include/ws_functions.inc.php b/include/ws_functions.inc.php index e61a4b2d6..ba7987c8e 100644 --- a/include/ws_functions.inc.php +++ b/include/ws_functions.inc.php @@ -934,7 +934,21 @@ SELECT 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 @@ -945,7 +959,10 @@ SELECT // 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); @@ -960,7 +977,21 @@ SELECT $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 @@ -975,7 +1006,10 @@ SELECT // 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); @@ -993,9 +1027,23 @@ SELECT $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', @@ -1006,7 +1054,10 @@ SELECT // 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); |