示例#1
0
function save_pic($url, $nick, $comment, $saved_file, $ext)
{
    global $fetch_log;
    $file_name = md5_file($saved_file);
    $path = STORAGE_PATH . $file_name . '.' . $ext;
    rename($saved_file, $path);
    $thumb_path = THUMB_PATH . $file_name . '.jpg';
    list($w, $h) = create_thumb($path, $thumb_path);
    chmod($path, 0664);
    chmod($thumb_path, 0664);
    $pic = new Pic(array('nick' => $nick, 'original_url' => $url, 'path' => $path, 'comment' => $comment, 'thumb' => $thumb_path, 'width' => $w, 'height' => $h, 'ctime' => date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME'])));
    if (ORM::all('pic', array('checksum' => $pic->checksum))->count() === 0) {
        if ($pic->save()) {
            file_put_contents($fetch_log, "[" . date('Y-m-d H:i:s') . "]\t{$nick}\tpic save SUCCESS\t{$url}\n", FILE_APPEND);
        } else {
            file_put_contents($fetch_log, "[" . date('Y-m-d H:i:s') . "]\t{$nick}\terror saving image: " . var_export($pic->errors(), true) . "\t{$url}\n", FILE_APPEND);
        }
    } else {
        file_put_contents($fetch_log, "[" . date('Y-m-d H:i:s') . "]\t{$nick}\tduplicate image\t{$url}\n", FILE_APPEND);
    }
}