ここの情報は古いです。ご理解頂いた上でお取り扱いください。

Changeset 6893


Ignore:
Timestamp:
May 1, 2008, 4:15:18 AM (11 years ago)
Author:
ebihara
Message:

c_imageテーブルに関する主要なDB関数をOpenPNE_Img_Storageに移動

Location:
OpenPNE/branches/work/ebihara/prj_renew_OpenPNE_Img/webapp/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • OpenPNE/branches/work/ebihara/prj_renew_OpenPNE_Img/webapp/lib/OpenPNE/Img/Storage.php

    r6892 r6893  
    4242    }
    4343
    44     function storeRawImage($filename, $bin, $type = '')
     44    function deleteImage($filename)
     45    {
     46        $sql = 'DELETE FROM c_image WHERE filename = ?';
     47        $params = array($filename);
     48        return $this->db->query($sql, $params);
     49    }
     50
     51    function storeImage($filename, $bin, $type = '')
    4552    {
    4653        $data = array(
     
    5158        );
    5259        return $this->db->insert($this->table, $data, $this->primary_key);
     60    }
     61
     62    function storeImageFromFile($filename, $filepath)
     63    {
     64        if (!is_readable($filepath)) return false;
     65
     66        $fp = fopen($filepath, 'rb');
     67        $image_data = fread($fp, filesize($filepath));
     68        fclose($fp);
     69
     70        // 画像かどうかのチェック
     71        if (!@imagecreatefromstring($image_data)) {
     72            return false;
     73        }
     74
     75        return $this->storeImage($filename, $image_data);
    5376    }
    5477
     
    6487        }
    6588    }
     89
     90    function isImageExists($filename)
     91    {
     92        $sql = 'SELECT c_image_id FROM c_image WHERE filename = ?';
     93        $params = array($filename);
     94        return (bool)$this->db->get_one($sql, $params);
     95    }
    6696}
    6797
  • OpenPNE/branches/work/ebihara/prj_renew_OpenPNE_Img/webapp/lib/db/image.php

    r6892 r6893  
    1616function db_image_is_c_image4filename($filename)
    1717{
    18     if (!$filename) return false;
    19 
    20     $db =& db_get_instance('image');
    21 
    22     $sql = 'SELECT c_image_id FROM c_image WHERE filename = ?';
    23     $params = array($filename);
    24     return (bool)$db->get_one($sql, $params);
     18    require_once 'OpenPNE/Img.php';
     19    $img =& new OpenPNE_Img();
     20    return $img->isImageExists($filename);
    2521}
    2622
     
    6258    require_once 'OpenPNE/Img.php';
    6359    $img =& new OpenPNE_Img();
    64     return $img->storage->storeRawImage($filename, $bin, $type);
     60    return $img->storage->storeImage($filename, $bin, $type);
    6561}
    6662
    6763function db_image_delete_c_image($filename)
    6864{
    69     $db =& db_get_instance('image');
    70 
    71     $sql = 'DELETE FROM c_image WHERE filename = ?';
    72     $params = array($filename);
    73     return $db->query($sql, $params);
     65    require_once 'OpenPNE/Img.php';
     66    $img =& new OpenPNE_Img();
     67    return $img->storage->deleteImage($filename);
    7468}
    7569
     
    7872function db_image_insert_c_image2($filename, $filepath)
    7973{
    80     if (!is_readable($filepath)) return false;
    81 
    82     $fp = fopen($filepath, 'rb');
    83     $image_data = fread($fp, filesize($filepath));
    84     fclose($fp);
    85 
    86     // 画像かどうかのチェック
    87     if (!@imagecreatefromstring($image_data)) return false;
    88 
    89     //TODO:typeフィールドを使う
    90     return db_image_insert_c_image($filename, $image_data);
     74    require_once 'OpenPNE/Img.php';
     75    $img =& new OpenPNE_Img();
     76    return $img->storage->storeImageFromFile($filename, $filepath);
    9177}
    9278
Note: See TracChangeset for help on using the changeset viewer.