コード例 #1
0
function cw_file_area_save($type, $for_customer_id, $data)
{
    global $tables, $customer_id, $var_dirs, $app_dir;
    $insert = array('customer_id' => $for_customer_id, 'by_customer_id' => $customer_id, 'filename' => $data['filename'], 'date' => cw_core_get_time(), 'md5' => md5(file_get_contents($data['file_path'])));
    if ($data['descr']) {
        $insert['descr'] = $data['descr'];
    }
    if ($data['id']) {
        $insert['id'] = $data['id'];
    }
    $file_id = cw_array2insert($type, $insert);
    if ($file_id) {
        $file_info = explode('.', $data['filename'], 2);
        $stored_file_name = $file_info[0] . '_' . $file_id . '.' . $file_info[1];
        $files_dir = $var_dirs['documents'] . '/' . $type;
        if (!is_dir($files_dir)) {
            @mkdir($files_dir);
        }
        $new_file_path = $files_dir . '/' . $stored_file_name;
        @copy($data['file_path'], $new_file_path);
        @unlink($data['file_path']);
        $new_file_path = cw_relative_path($new_file_path, $app_dir);
        db_query("update " . $tables[$type] . " set file_path='" . addslashes($new_file_path) . "' where file_id='{$file_id}'");
    }
    return $file_id;
}
コード例 #2
0
function cw_image_delete_all($type = '', $where = '')
{
    global $available_images, $tables, $app_dir;
    if (!isset($available_images[$type])) {
        return false;
    }
    if (!empty($where)) {
        $where = " where " . $where;
    }
    $_table = $tables[$type];
    if (cw_query_first_cell("select count(*) from " . $_table . $where) == 0) {
        return false;
    }
    $res = db_query("SELECT image_id, image_path, filename FROM " . $_table . $where);
    if ($res) {
        cw_load('image');
        $img_dir = cw_image_dir($type) . "/";
        while ($v = db_fetch_array($res)) {
            if (!zerolen($v['image_path']) && is_url($v['image_path'])) {
                continue;
            }
            $image_path = $v['image_path'];
            if (zerolen($image_path)) {
                $image_path = cw_relative_path($img_dir . $v['filename']);
            }
            $is_found = false;
            # check other types
            foreach ($available_images as $k => $i) {
                $is_found = cw_query_first_cell("select count(*) from " . $tables[$k] . " where image_path='" . addslashes($image_path) . "'" . ($k == $type ? " AND image_id != '{$v['image_id']}'" : "")) > 0;
                if ($is_found) {
                    break;
                }
            }
            if (!$is_found && file_exists($image_path)) {
                @unlink($image_path);
                if ($type == 'products_images_thumb') {
                    cw_rm_dir($img_dir . '/' . $v['image_id']);
                }
            }
        }
        db_free_result($res);
    }
    db_query("delete from " . $_table . $where);
    return true;
}