Changeset 2785


Ignore:
Timestamp:
Oct 20, 2008, 11:04:17 PM (16 years ago)
Author:
plg
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.0/include/ws_functions.inc.php

    r2765 r2785  
    935935    umask(0000);
    936936    $recursive = true;
    937     mkdir($upload_dir, 0777, $recursive);
     937    if (!@mkdir($upload_dir, 0777, $recursive))
     938    {
     939      return new PwgError(500, 'error during directory creation');
     940    }
     941  }
     942
     943  if (!is_writable($upload_dir))
     944  {
     945    // last chance to make the directory writable
     946    @chmod($upload_dir, 0777);
     947
     948    if (!is_writable($upload_dir))
     949    {
     950      return new PwgError(500, 'directory has no write access');
     951    }
    938952  }
    939953
     
    946960  // dump the photo file
    947961  $fh_file = fopen($file_path, 'w');
    948   fwrite($fh_file, base64_decode($params['file_content']));
     962  if (!fwrite($fh_file, base64_decode($params['file_content'])))
     963  {
     964    return new PwgError(500, 'error while writing file');
     965  }
    949966  fclose($fh_file);
    950967  chmod($file_path, 0644);
     
    961978  if (!is_dir($thumbnail_dir)) {
    962979    umask(0000);
    963     mkdir($thumbnail_dir, 0777);
     980    if (!@mkdir($thumbnail_dir, 0777))
     981    {
     982      return new PwgError(500, 'error during thumbnail directory creation');
     983    }
     984  }
     985
     986  if (!is_writable($thumbnail_dir))
     987  {
     988    // last chance to make the directory writable
     989    @chmod($thumbnail_dir, 0777);
     990
     991    if (!is_writable($thumbnail_dir))
     992    {
     993      return new PwgError(500, 'thumbnail directory has no write access');
     994    }
    964995  }
    965996
     
    9761007  // dump the thumbnail
    9771008  $fh_thumbnail = fopen($thumbnail_path, 'w');
    978   fwrite($fh_thumbnail, base64_decode($params['thumbnail_content']));
     1009  if (!fwrite($fh_thumbnail, base64_decode($params['thumbnail_content'])))
     1010  {
     1011    return new PwgError(500, 'error while writing thumbnail');
     1012  }
    9791013  fclose($fh_thumbnail);
    9801014  chmod($thumbnail_path, 0644);
     
    9941028    if (!is_dir($high_dir)) {
    9951029      umask(0000);
    996       mkdir($high_dir, 0777);
    997     }
    998 
     1030      if (!@mkdir($high_dir, 0777))
     1031      {
     1032        return new PwgError(500, 'error during high directory creation');
     1033      }
     1034    }
     1035
     1036    if (!is_writable($high_dir))
     1037    {
     1038      // last chance to make the directory writable
     1039      @chmod($high_dir, 0777);
     1040     
     1041      if (!is_writable($high_dir))
     1042      {
     1043        return new PwgError(500, 'high directory has no write access');
     1044      }
     1045    }
     1046   
    9991047    // high resolution path, same name as web size file
    10001048    $high_path = sprintf(
     
    10071055    // dump the high resolution file
    10081056    $fh_high = fopen($high_path, 'w');
    1009     fwrite($fh_high, base64_decode($params['high_content']));
     1057    if (!fwrite($fh_high, base64_decode($params['high_content'])))
     1058    {
     1059      return new PwgError(500, 'error while writing high');
     1060    }
    10101061    fclose($fh_high);
    10111062    chmod($high_path, 0644);
Note: See TracChangeset for help on using the changeset viewer.