Changeset 2683 for trunk/include


Ignore:
Timestamp:
Oct 8, 2008, 12:01:14 AM (16 years ago)
Author:
plg
Message:

feature 889 added: pwg.images.exist check the existence of a photo in the
database based on its md5sum. (avoid failing on pwg.images.add).

File:
1 edited

Legend:

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

    r2672 r2683  
    14581458  return $creation_output;
    14591459}
     1460
     1461function ws_images_exist($params, &$service)
     1462{
     1463  if (!is_admin() or is_adviser())
     1464  {
     1465    return new PwgError(401, 'Access denied');
     1466  }
     1467
     1468  // search among photos the list of photos already added, based on md5sum
     1469  // list
     1470  $md5sums = preg_split(
     1471    '/[\s,;\|]/',
     1472    $params['md5sum_list'],
     1473    -1,
     1474    PREG_SPLIT_NO_EMPTY
     1475    );
     1476 
     1477  $query = '
     1478SELECT
     1479    id,
     1480    md5sum
     1481  FROM '.IMAGES_TABLE.'
     1482  WHERE md5sum IN (\''.implode("','", $md5sums).'\') 
     1483;';
     1484  $id_of_md5 = simple_hash_from_query($query, 'md5sum', 'id');
     1485
     1486  $result = array();
     1487 
     1488  foreach ($md5sums as $md5sum)
     1489  {
     1490    $result[$md5sum] = null;
     1491    if (isset($id_of_md5[$md5sum]))
     1492    {
     1493      $result[$md5sum] = $id_of_md5[$md5sum];
     1494    }
     1495  }
     1496
     1497  return $result;
     1498}
    14601499?>
Note: See TracChangeset for help on using the changeset viewer.