Ejemplo n.º 1
0
function upload_image($input, $image = null, $type = 'page', $scale = false)
{
    $year = date('Y');
    $day = date('md');
    $n = time() . rand(1000, 9999) . '.jpg';
    $z = $_FILES[$input];
    if ($z && strpos($z['type'], 'image') === 0 && $z['error'] == 0) {
        if (!$image) {
            RecursiveMkdir(IMG_ROOT . '/' . "{$type}/{$year}/{$day}");
            $image = "{$type}/{$year}/{$day}/{$n}";
            $path = IMG_ROOT . '/' . $image;
        } else {
            RecursiveMkdir(dirname(IMG_ROOT . '/' . $image));
            $path = IMG_ROOT . '/' . $image;
            $postfixs = array_keys(get_image_size_map());
            // $postfixs = array('_index','_big');
            foreach ($postfixs as $fix) {
                $index_image = preg_replace('#(\\w+)\\.(\\w+)$#', "\\1_{$fix}.\\2", $path);
                unlink($index_image);
            }
        }
        move_uploaded_file($z['tmp_name'], $path);
        return $image;
    }
    return $image;
}
Ejemplo n.º 2
0
function get_page_screenshot($url, $image, $width = 600)
{
    if (!$width) {
        $width = 600;
    }
    $shot_server = 'http://shot.lhls.com.cn/shot.php';
    $img_content = Utility::DoGet($shot_server . '?w=' . $width . '&url=' . urlencode($url));
    if (!$img_content) {
        return null;
    }
    // 如果存在原图,将原图的各个后缀的预览图删除
    if ($image) {
        RecursiveMkdir(dirname(IMG_ROOT . '/' . $image));
        $postfixs = array_keys(get_image_size_map());
        foreach ($postfixs as $fix) {
            $index_image = preg_replace('#(\\w+)\\.(\\w+)$#', "\\1_{$fix}.\\2", $path);
            unlink($index_image);
        }
    } else {
        $year = date('Y');
        $day = date('md');
        $n = time() . rand(1000, 9999) . '.jpg';
        $full_path = IMG_ROOT . "/screenshot/{$year}/{$day}";
        RecursiveMkdir($full_path);
        $image = "/screenshot/{$year}/{$day}/{$n}";
    }
    $path = str_replace('//', '/', IMG_ROOT . '/' . $image);
    $fimage = fopen($path, 'w');
    fwrite($fimage, $img_content);
    fclose($fimage);
    return $image;
}