Ejemplo n.º 1
0
function photoalbum_upload_photo($filename, $user, $options = null)
{
    $category = isset($options['category']) ? $options['category'] : 4;
    /* Default to 8 if category is not set */
    $description = isset($options['description']) ? $options['description'] : null;
    $query = 'SELECT photos FROM photo_albums WHERE owner = "' . $user . '" AND position = "' . $category . '" LIMIT 1';
    $result = mysql_query($query) or die(report_sql_error($query, __FILE__, __LINE__));
    $data = mysql_fetch_assoc($result);
    $images_string = $data['photos'];
    $existing_images = substr_count($data['photos'], ',');
    if ($existing_images == 0) {
        $existing_images = strlen($existing_images) > 0 ? 1 : 0;
    } else {
        $existing_images = $existing_images + 1;
    }
    if ($existing_images > 9) {
        return array('status' => 'fail', 'reason' => 'Fotoalbumet är fullt');
    }
    $copy_data = read_copy_protection($filename);
    if ($copy_data['copyright'] == 1 && $_SESSION['login']['id'] != $copy_data['userid']) {
        return array('status' => 'fail', 'reason' => 'Bilden du försöker ladda upp är upphovsrättsskyddad, och kunde därför inte laddas upp');
    }
    $query = 'INSERT INTO photos (owner, timestamp, description) VALUES(' . $user . ', ' . time() . ', "' . $description . '")';
    mysql_query($query) or die(report_sql_error($query, __FILE__, __LINE__));
    $image_id = mysql_insert_id();
    $save_path = PATHS_IMAGES . 'photoalbums/images_' . round($image_id / 1000) . '/' . $image_id;
    if (!is_dir(PATHS_IMAGES . 'photoalbums/images_' . round($image_id / 1000))) {
        if (!mkdir(PATHS_IMAGES . 'photoalbums/images_' . round($image_id / 1000))) {
            to_logfile('error', __FILE__, __LINE__, 'Could not create directory', PATHS_IMAGES . 'photoalbums/images_' . round($image_id / 1000));
            return array('status' => 'fail', 'reason' => 'could not create directory');
        }
    }
    print_r($options);
    list($info_width, $info_height, $info_type, $info_attr) = getimagesize($filename);
    if ($info_width < 400 && $info_height < 300) {
        system('convert ' . $filename . ' ' . $save_path . '_full.jpg');
    } else {
        system('convert ' . $filename . ' -resize 400x300 ' . $save_path . '_full.jpg');
    }
    system('convert ' . $filename . ' -resize 60x45! ' . $save_path . '_thumb.jpg');
    /* ! disregards image proportions */
    /* Copyright info has to be written after resize, since it only works for JPEG files */
    if ($options['copyright'] == 'true') {
        write_copy_protection($save_path . '_full.jpg', 'Copyrighted Work');
        write_copy_protection($save_path . '_thumb.jpg', 'Copyrighted Work');
    } else {
        write_copy_protection($save_path . '_full.jpg', '');
        write_copy_protection($save_path . '_thumb.jpg', '');
    }
    unlink($filename);
    $images_string = strlen($images_string) > 0 ? $images_string . ',' . $image_id : $image_id;
    $query = 'UPDATE photo_albums SET photos = "' . $images_string . '" WHERE owner = "' . $user . '" AND position = "' . $category . '"';
    mysql_query($query) or die(report_sql_error($query, __FILE__, __LINE__));
    if (mysql_affected_rows() == 0) {
        return array('status' => 'fail', 'reason' => 'photo album does not exist!');
    }
    return array('status' => 'success', 'id' => $image_id);
}
Ejemplo n.º 2
0
	<input type="button" class="button" value="Nej tack, jag vill inte ladda upp en bild &raquo;"	onclick="location.href=\'/register.php?nextstep=3\'">';
    }
    $out .= '</form>';
    $avatar_full_filename = $avatar_path_full . $_SESSION['login']['id'] . '.jpg';
    if (is_file($avatar_full_filename)) {
        $out .= '<h2 style="margin: 0px; ">Din nuvarande bild:</h2>';
        $out .= insert_avatar($_SESSION['login']['id'], 'style="border: 1px solid #333333;"');
        $out .= '<br /><b><a href="' . $_SERVER['PHP_SELF'] . '?action=delete">» Ta bort bilden</a></b>';
    }
} elseif ($_GET['step'] == '2') {
    if (!is_file($avatar_tmp_orginal_filename)) {
        jscript_alert('Någonting blev fel vid uppladdningen av bilden, försök igen!');
        jscript_go_back();
        die;
    }
    $copy_data = read_copy_protection($avatar_tmp_orginal_filename);
    if ($copy_data['copyright'] == 1 && $_SESSION['login']['id'] != $copy_data['userid']) {
        jscript_alert('Den gubben gick inte');
        jscript_go_back();
        die;
    }
    $avatar_height = intval(exec('identify ' . $avatar_tmp_orginal_filename . ' | cut -f3 -d" " | cut -f2 -d"x" | cut -f1 -d"+"'));
    $flash_height = $avatar_height + 70;
    //$crop_width = $avatar_height * 0.75;
    $crop_width = intval($avatar_height * 0.75);
    $out .= '<h1 style="margin: 0px; ">Skala och besk&auml;r ditt foto (steg 2)</h1>';
    $out .= 'Här kan du beskära och klippa ut valt område från ditt foto. Alla foton kommer klippas ut med ration 3:4.<br /><br />';
    $out .= '» Vill du ladda upp en annan bild så gå tillbaka till <a href="avatar-settings.php';
    if (isset($_GET['registerproccess'])) {
        $out .= '?registerproccess=1';
    }