Exemple #1
0
    case 'image/jpeg':
        $extension = 'jpg';
        break;
    case 'image/png':
        $extension = 'png';
        break;
    default:
        $finfo = finfo_open($tmp_path, FILEINFO_MIME_TYPE);
        $finfo_mime = finfo_file($finfo, $tmp_path);
        finfo_close($finfo);
        file_put_contents($fetch_log, "[" . date('Y-m-d H:i:s') . "]\t{$nick}\tcant recognize mime type: '{$image_info['mime']}', fileinfo says its a '{$finfo_mime}', saving as link\t{$url}\n", FILE_APPEND);
        save_link($type, $size, $url, $nick, $tmp_path);
        exit;
        break;
}
save_pic($url, $nick, $comment, $tmp_path, $extension);
build_rss_files();
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);
Exemple #2
0
         $_SGLOBAL['db']->query("UPDATE " . tname('blog') . " SET pic='{$newpath}' WHERE blogid='{$blog['blogid']}'");
         $_SGLOBAL['db']->query("UPDATE " . tname('feed') . " SET image_1='{$newpath}' WHERE dateline>{$lastDay} AND image_1='{$blog['pic']}'");
         //echo "--->pic update OK--->";
     }
 }
 $pattern_src = '/<[img|IMG].*?src=[\'|\\"](.*?(?:[\\.gif|\\.jpg\\|.png|\\.jpge]))[\'|\\"].*?[\\/]?>/';
 $num = preg_match_all($pattern_src, $blog['message'], $match_src);
 $pic_arr = $match_src[1];
 //获得图片数组
 //print_r($pic_arr);
 $isReplaced = false;
 $newContent = $blog['message'];
 foreach ($pic_arr as $pic_item) {
     //循环取出每幅图的地址
     if (isOutSitePic($pic_item)) {
         $newpath = save_pic($pic_item, $path);
         //下载并保存图片
         if ($newpath) {
             $newContent = str_replace($pic_item, $newpath, $newContent);
             //echo $newContent;
             //echo '--->content pic new path--->'.$newpath.'--->';
             $isReplaced = true;
         }
     }
 }
 if ($isReplaced) {
     //print_r($blog['message']);
     $newContent = addslashes($newContent);
     $_SGLOBAL['db']->query("UPDATE " . tname('blogfield') . " SET message='{$newContent}' WHERE blogid='{$blog['blogid']}'");
     //echo "content pics update OK".$blog['blogid'];
 }