Example #1
0
function avatars_manage_upload($user, $name)
{
    global $globals;
    $subdir = get_avatars_dir() . '/' . intval($user / $globals['avatars_files_per_dir']);
    $file_base = $subdir . '/' . $user;
    @mkdir(get_avatars_dir());
    @mkdir($subdir);
    if (!is_writable($subdir)) {
        return false;
    }
    avatars_remove_user_files($user);
    move_uploaded_file($_FILES[$name]['tmp_name'], $file_base . '-orig.img');
    $size = @getimagesize("{$file_base}-orig.img");
    avatar_resize("{$file_base}-orig.img", "{$file_base}-80.jpg", 80);
    $size = @getimagesize("{$file_base}-80.jpg");
    if (!($size[0] == 80 && $size[1] == 80 && avatars_db_store($user, "{$file_base}-80.jpg"))) {
        // Mark FALSE in DB
        avatars_db_remove($user);
        avatars_remove_user_files($user);
        return false;
    }
    // Upload to DB and mark TRUE
    avatar_resize("{$file_base}-orig.img", "{$file_base}-20.jpg", 20);
    avatar_resize("{$file_base}-orig.img", "{$file_base}-25.jpg", 25);
    avatar_resize("{$file_base}-orig.img", "{$file_base}-40.jpg", 40);
    unlink("{$file_base}-orig.img");
    return true;
}
Example #2
0
function avatars_manage_upload($user, $name)
{
    global $globals;
    $subdir = get_avatars_dir() . '/' . intval($user / $globals['avatars_files_per_dir']);
    $file_base = $subdir . '/' . $user;
    @mkdir($subdir);
    avatars_remove_user_files($user);
    move_uploaded_file($_FILES[$name]['tmp_name'], $file_base . '-orig.img');
    $size = @getimagesize("{$file_base}-orig.img");
    system("convert -quality 85 -resize 80x80! {$file_base}-orig.img {$file_base}-80.jpg");
    $size = @getimagesize("{$file_base}-80.jpg");
    if (!($size[0] == 80 && $size[1] == 80 && avatars_db_store($user, "{$file_base}-80.jpg"))) {
        // Mark FALSE in DB
        avatars_db_remove($user);
        avatars_remove_user_files($user);
        return false;
    }
    // Upload to DB and mark TRUE
    system("convert -quality 85 -resize 20x20 {$file_base}-orig.img {$file_base}-20.jpg");
    system("convert -quality 85 -resize 25x25 {$file_base}-orig.img {$file_base}-25.jpg");
    unlink("{$file_base}-orig.img");
    return true;
}
Example #3
0
function avatars_manage_upload($user, $name, $filename = false)
{
    global $globals;
    $time = $globals['now'];
    if (!$globals['Amazon_S3_local_cache'] && $globals['Amazon_S3_media_bucket'] && is_writable('/tmp')) {
        $subdir = '/tmp';
    } else {
        $chain = get_cache_dir_chain($user);
        @mkdir(get_avatars_dir());
        create_cache_dir_chain(get_avatars_dir(), $chain);
        $subdir = get_avatars_dir() . '/' . $chain;
    }
    if (!is_writable($subdir)) {
        return false;
    }
    $file_base = $subdir . "/{$user}-{$time}";
    // First check the image is valid before moving and deleting
    // If $name is provided, the file was uploaded from a form
    if ($name) {
        $filename = $_FILES[$name]['tmp_name'];
    }
    $original_size = @getimagesize($filename);
    if ($original_size == false) {
        @unlink($filename);
        return false;
    }
    avatars_remove_user_files($user);
    // If $name is provided, the file was uploaded from a form
    if ($name) {
        move_uploaded_file($filename, $file_base . '-orig.img');
    } else {
        rename($filename, $file_base . '-orig.img');
    }
    avatar_resize("{$file_base}-orig.img", "{$file_base}-80.jpg", 80);
    $size = @getimagesize("{$file_base}-80.jpg");
    if (!($size[0] == 80 && $size[1] == 80 && ($mtime = avatars_db_store($user, "{$file_base}-80.jpg", $time)))) {
        // Mark FALSE in DB
        avatars_db_remove($user);
        avatars_remove_user_files($user);
        return false;
    }
    avatar_resize("{$file_base}-orig.img", "{$file_base}-20.jpg", 20);
    avatar_resize("{$file_base}-orig.img", "{$file_base}-25.jpg", 25);
    avatar_resize("{$file_base}-orig.img", "{$file_base}-40.jpg", 40);
    // Store in S3 the other images and a higher quality one
    if ($globals['Amazon_S3_media_bucket']) {
        $max_size = min($original_size[0], $original_size[1], 200);
        avatar_resize("{$file_base}-orig.img", "{$file_base}.jpg", $max_size);
        if (Media::put("{$file_base}-20.jpg", 'avatars') && Media::put("{$file_base}-25.jpg", 'avatars') && Media::put("{$file_base}-40.jpg", 'avatars') && Media::put("{$file_base}.jpg", 'avatars')) {
            @unlink("{$file_base}.jpg");
            if (!$globals['Amazon_S3_local_cache']) {
                @unlink("{$file_base}-20.jpg");
                @unlink("{$file_base}-25.jpg");
                @unlink("{$file_base}-40.jpg");
                @unlink("{$file_base}-80.jpg");
            }
        }
    }
    @unlink("{$file_base}-orig.img");
    return $mtime;
}
Example #4
0
function avatars_manage_upload($user, $name, $filename = false)
{
    global $globals;
    $time = $globals['now'];
    if (!$globals['Amazon_S3_local_cache'] && $globals['Amazon_S3_media_bucket'] && is_writable('/tmp')) {
        $subdir = '/tmp';
    } else {
        if (!Upload::create_cache_dir($user)) {
            return false;
        }
        $subdir = Upload::get_cache_dir($user);
    }
    if (!is_writable($subdir)) {
        return false;
    }
    $file_base = $subdir . "/{$user}-{$time}";
    // First check the image is valid before moving and deleting
    // If $name is provided, the file was uploaded from a form
    if ($name) {
        $filename = $_FILES[$name]['tmp_name'];
    }
    $original_size = @getimagesize($filename);
    if ($original_size == false) {
        @unlink($filename);
        return false;
    }
    avatars_remove_user_files($user);
    // If $name is provided, the file was uploaded from a form
    if ($name) {
        move_uploaded_file($filename, $file_base . '-orig.img');
    } else {
        $r = copy($filename, $file_base . '-orig.img');
        @unlink($filename);
        if (!$r) {
            syslog(LOG_INFO, "Error copying avatar from {$filename} to {$file_base}" . '-orig.img');
            return false;
        }
    }
    avatar_resize("{$file_base}-orig.img", "{$file_base}-80.jpg", 80);
    $size = @getimagesize("{$file_base}-80.jpg");
    if (!($size[0] == 80 && $size[1] == 80 && ($mtime = avatars_db_store($user, "{$file_base}-80.jpg", $time)))) {
        // Mark FALSE in DB
        avatars_db_remove($user);
        avatars_remove_user_files($user);
        return false;
    }
    foreach ($globals['avatars_allowed_sizes'] as $size) {
        if ($size != 80) {
            avatar_resize("{$file_base}-orig.img", "{$file_base}-{$size}.jpg", $size);
        }
    }
    // Store in S3 the other images and a higher quality one
    if ($globals['Amazon_S3_media_bucket']) {
        $max_size = min($original_size[0], $original_size[1], 200);
        avatar_resize("{$file_base}-orig.img", "{$file_base}.jpg", $max_size);
        if (Media::put("{$file_base}-20.jpg", 'avatars') && Media::put("{$file_base}-25.jpg", 'avatars') && Media::put("{$file_base}-40.jpg", 'avatars') && Media::put("{$file_base}.jpg", 'avatars')) {
            @unlink("{$file_base}.jpg");
            if (!$globals['Amazon_S3_local_cache']) {
                @unlink("{$file_base}-20.jpg");
                @unlink("{$file_base}-25.jpg");
                @unlink("{$file_base}-40.jpg");
                @unlink("{$file_base}-80.jpg");
            }
        }
    }
    @unlink("{$file_base}-orig.img");
    return $mtime;
}