Exemple #1
0
 public static function uploadViaUrl($url, $options, &$error)
 {
     $urlInfo = parse_url($url);
     $file_name = basename($urlInfo['path']);
     $file_path = $options['bucket'] . '/' . ($options['use_filename'] ? $options['use_filename'] : $file_name);
     $real_file_path = MEDIA_DIR . '/' . $file_path;
     if (!self::makeFileStorageDir($real_file_path)) {
         Log::getInstance()->error("Can not make storage directory {$real_file_path}");
         return false;
     }
     if (!$options['overwrite'] && file_exists($real_file_path)) {
         Log::getInstance()->info("{$real_file_path} existed!");
         return 'media/' . $file_path;
     }
     if (self::crawlImgViaUrl($url, $real_file_path)) {
         return 'media/' . $file_path;
     } else {
         Log::getInstance()->warning("Can not crawl image via link: {$url}");
     }
     return false;
 }
Exemple #2
0
Loader::register();
$app = new \Slim\Slim(array('debug' => true, 'mode' => 'development'));
$app->get('/cache/:function/:dimension/:path+', function ($function, $dimension, $path) use($app) {
    $path = implode(DIRECTORY_SEPARATOR, $path);
    $public_dir = rtrim(dirname(MEDIA_DIR), '/');
    //check file exists
    if (!file_exists($public_dir . '/' . $path)) {
        //throw 404
        $app->halt(404, 'File not found!');
    }
    try {
        $dimension = explode('-', $dimension);
        $params = \SFS\Image\Transform::hydrateParameters($dimension);
        $imgTransform = new \SFS\Image\Transform($public_dir . '/' . $path);
        if (!method_exists($imgTransform, $function)) {
            $app->halt(400, 'Not support API "' . $function . '"');
            exit;
        }
        $imgTransform->{$function}($params);
        $dimension = implode('-', $dimension);
        $output = "{$public_dir}/thumbs/cache/{$function}/{$dimension}/{$path}";
        \SFS\Upload::makeFileStorageDir($output);
        $imgTransform->save($output);
        $imgTransform->display();
        exit;
    } catch (\Exception $e) {
        \SFS\Log::getInstance()->error($e->getMessage() . "\nTrances:\n" . $e->getTraceAsString());
        $app->halt(500, 'Error occur:');
    }
});
$app->run();