diff options
author | plegall <plg@piwigo.org> | 2008-10-20 21:04:17 +0000 |
---|---|---|
committer | plegall <plg@piwigo.org> | 2008-10-20 21:04:17 +0000 |
commit | 39eb742c25ca2804eb4453e65449d433e1db389a (patch) | |
tree | f8502bd4986a06bcc0094bce4c1880101672b6f3 /include | |
parent | 2a162361dd224bcb8e842148489e230ab7b395be (diff) |
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/branches/2.0@2785 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'include')
-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 4bf48578a..24170ec47 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); |