Changeset 2501


Ignore:
Timestamp:
Sep 5, 2008, 12:45:27 AM (16 years ago)
Author:
plg
Message:

improvement: ws method pwg.images.add checks the dumped files against the
expected md5 sum.

bug fixed: ws method pwg.images.add invalidate the user cache so that
category date_last and category nb_images (and related data)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/ws_functions.inc.php

    r2496 r2501  
    940940  list($year, $month, $day) = preg_split('/[^\d]/', $dbnow, 4);
    941941
     942  // upload directory hierarchy
    942943  $upload_dir = sprintf(
    943944    PHPWG_ROOT_PATH.'upload/%s/%s/%s',
     
    949950  //fwrite($fh_log, $upload_dir."\n");
    950951
     952  // create the upload directory tree if not exists
    951953  if (!is_dir($upload_dir)) {
    952954    umask(0000);
     
    955957  }
    956958
     959  // compute file path
    957960  $date_string = preg_replace('/[^\d]/', '', $dbnow);
    958961  $random_string = substr($params['file_sum'], 0, 8);
    959 
    960962  $filename_wo_ext = $date_string.'-'.$random_string;
    961 
    962963  $file_path = $upload_dir.'/'.$filename_wo_ext.'.jpg';
     964
     965  // dump the photo file
    963966  $fh_file = fopen($file_path, 'w');
    964967  fwrite($fh_file, base64_decode($params['file_content']));
    965968  fclose($fh_file);
    966969
    967   // check dumped file md5sum with expected md5sum
    968 
     970  // check dumped file md5sum against expected md5sum
     971  $dumped_md5 = md5_file($file_path);
     972  if ($dumped_md5 != $params['file_sum']) {
     973    return new PwgError(500, 'file transfert failed');
     974  }
     975
     976  // thumbnail directory is a subdirectory of the photo file, hard coded
     977  // "thumbnail"
    969978  $thumbnail_dir = $upload_dir.'/thumbnail';
    970979  if (!is_dir($thumbnail_dir)) {
     
    973982  }
    974983
     984  // thumbnail path, the filename may use a prefix and the extension is
     985  // always "jpg" (no matter what the real file format is)
    975986  $thumbnail_path = sprintf(
    976987    '%s/%s%s.%s',
     
    980991    'jpg'
    981992    );
     993
     994  // dump the thumbnail
    982995  $fh_thumbnail = fopen($thumbnail_path, 'w');
    983996  fwrite($fh_thumbnail, base64_decode($params['thumbnail_content']));
     
    985998
    986999  // check dumped thumbnail md5
     1000  $dumped_md5 = md5_file($thumbnail_path);
     1001  if ($dumped_md5 != $params['thumbnail_sum']) {
     1002    return new PwgError(500, 'thumbnail transfert failed');
     1003  }
    9871004
    9881005  // fwrite($fh_log, 'output: '.md5_file($file_path)."\n");
     
    10161033    array($insert)
    10171034    );
     1035
     1036  invalidate_user_cache();
    10181037
    10191038  // fclose($fh_log);
Note: See TracChangeset for help on using the changeset viewer.