Esempio n. 1
0
function account_user_upload()
{
    global $db;
    if ($db->result(DB_PRE . 'ecp_user', 'user_pic', 'ID = ' . $_SESSION['userID']) != '') {
        table(ERROR, ACCOUNT_USERPIC_EXIST);
        account_user_pics();
    } else {
        if ($_FILES['user']['size'] > USER_PIC_MAX) {
            table(ERROR, str_replace('{oversize}', goodsize($_FILES['user']['size'] - USER_PIC_MAX), ACCOUNT_USERPIC_TO_BIG));
            account_user_pics();
        } elseif (count(getimagesize($_FILES['user']['tmp_name'])) < 2) {
            table(ERROR, ACCOUNT_WRONG_FILE_TYPE);
            account_user_pics();
        } else {
            $size = getimagesize($_FILES['user']['tmp_name']);
            print_r($size);
            $xmore = $size[0] - USER_PIC_X;
            $ymore = $size[1] - USER_PIC_Y;
            $sha1 = sha1_file($_FILES['user']['tmp_name']) . '.' . str_replace('image/', '', $size['mime']);
            if (($xmore > 0 or $ymore > 0) and ($size['mime'] == 'image/jpeg' or $size['mime'] == 'image/pjpeg' or $size['mime'] == 'image/jpg')) {
                if ($xmore > $ymore) {
                    resize_picture($_FILES['user']['tmp_name'], USER_PIC_X, 'images/user/' . $_SESSION['userID'] . '_' . $sha1, 85, 1);
                } else {
                    resize_picture($_FILES['user']['tmp_name'], USER_PIC_Y, 'images/user/' . $_SESSION['userID'] . '_' . $sha1, 85, 0);
                }
                if ($db->query('UPDATE ' . DB_PRE . 'ecp_user SET user_pic = \'' . strsave($sha1) . '\' WHERE ID = ' . $_SESSION['userID'])) {
                    header1('?section=account&action=avatar');
                }
            } elseif ($size[0] > USER_PIC_X or $size[1] > USER_PIC_Y) {
                table(ERROR, ACCOUNT_USERPIC_TO_BIG2);
                account_user_pics();
            } else {
                if (move_uploaded_file($_FILES['user']['tmp_name'], 'images/user/' . $_SESSION['userID'] . '_' . $sha1)) {
                    umask(0);
                    chmod('images/user/' . $_SESSION['userID'] . '_' . $sha1, CHMOD);
                    if ($db->query('UPDATE ' . DB_PRE . 'ecp_user SET user_pic = \'' . strsave($sha1) . '\' WHERE ID = ' . $_SESSION['userID'])) {
                        header1('?section=account&action=avatar');
                    }
                }
            }
        }
    }
}
#
# Requires: php-amqplib
#
# Author: Alvaro Videla
# (C)2010
###############################################
require_once '../lib/php-amqplib/amqp.inc';
require_once '../config/config.php';
$conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);
$channel = $conn->channel();
$channel->exchange_declare('upload-pictures', 'fanout', false, true, false);
$channel->queue_declare('resize-picture', false, true, false, false);
$channel->queue_bind('resize-picture', 'upload-pictures');
$consumer = function ($msg) {
    if ($msg->body == 'quit') {
        $msg->delivery_info['channel']->basic_cancel($msg->delivery_info['consumer_tag']);
    }
    $meta = json_decode($msg->body, true);
    resize_picture($meta['image_id'], $meta['image_path']);
    $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
};
function resize_picture($image_id, $image_path)
{
    echo sprintf("Resizing picture: %s %s\n", $image_id, $image_path);
}
$channel->basic_consume($queue, $consumer_tag, false, false, false, false, $consumer);
while (count($channel->callbacks)) {
    $channel->wait();
}
$channel->close();
$conn->close();
Esempio n. 3
0
                 if ($db->query('INSERT INTO ' . DB_PRE . 'ecp_gallery_images (`gID`, `filename`, `uploaded`, `userID`) VALUES (' . (int) $_GET['id'] . ', \'' . $sha1 . '.jpg\', ' . time() . ', ' . (int) $_SESSION['userID'] . ')')) {
                     $id = $db->last_id();
                     $db->query('UPDATE ' . DB_PRE . 'ecp_gallery SET images = images + 1 WHERE galleryID= ' . (int) $_GET['id']);
                     if (move_uploaded_file($_FILES[$key]['tmp_name'], 'images/gallery/' . $gallery['folder'] . '/' . $id . '_' . $sha1 . '.jpg')) {
                         umask(0);
                         chmod('images/gallery/' . $gallery['folder'] . '/' . $id . '_' . $sha1 . '.jpg', CHMOD);
                         $size = getimagesize('images/gallery/' . $gallery['folder'] . '/' . $id . '_' . $sha1 . '.jpg');
                         if ($size[0] > GALLERY_THUMB_SIZE) {
                             resize_picture('images/gallery/' . $gallery['folder'] . '/' . $id . '_' . $sha1 . '.jpg', GALLERY_THUMB_SIZE, 'images/gallery/' . $gallery['folder'] . '/thumbs/' . $id . '_' . $sha1 . '.jpg', 100, 0);
                         } else {
                             copy('images/gallery/' . $gallery['folder'] . '/' . $id . '_' . $sha1 . '.jpg', 'images/gallery/' . $gallery['folder'] . '/thumbs/' . $id . '_' . $sha1 . '.jpg');
                             umask(0);
                             chmod('images/gallery/' . $gallery['folder'] . '/thumbs/' . $id . '_' . $sha1 . '.jpg', CHMOD);
                         }
                         if ($size[0] > GALLERY_PIC_SIZE) {
                             resize_picture('images/gallery/' . $gallery['folder'] . '/' . $id . '_' . $sha1 . '.jpg', GALLERY_PIC_SIZE, 'images/gallery/' . $gallery['folder'] . '/' . $id . '_' . $sha1 . '.jpg', 100);
                         }
                     } else {
                         @($error .= 'Datei konnte nicht verschoben werden.(' . $_FILES[$key]['name'] . ')<br />');
                     }
                 }
             } else {
                 @($error .= WRONG_FILE_TYPE . ' (' . $_FILES[$key]['name'] . ' : ' . getMimeType($_FILES[$key]['tmp_name'], $_FILES[$key]['name']) . ')<br />');
             }
         }
     } else {
         $error = FILE_NOT_FOUND;
     }
 } else {
     $error = FILE_EXIST;
 }
Esempio n. 4
0
function ordner_einlesen($id)
{
    global $db;
    $verzeichnis = $db->result(DB_PRE . 'ecp_gallery', 'folder', 'galleryID = ' . $id);
    $files = scan_dir('images/gallery/' . $verzeichnis, true);
    $result = $db->query('SELECT imageID, filename FROM ' . DB_PRE . 'ecp_gallery_images WHERE gID = ' . $id);
    $bilder = array();
    while ($row = $db->fetch_assoc()) {
        $bilder[$row['imageID'] . '_' . $row['filename']] = 0;
    }
    print_r($files);
    print_r($bilder);
    if (!file_exists('images/gallery/' . $verzeichnis . '/thumbs')) {
        umask(0);
        mkdir('images/gallery/' . $verzeichnis . '/thumbs', 0777);
    }
    foreach ($files as $name) {
        if (strpos($name, '.')) {
            if (array_key_exists($name, $bilder)) {
                $bilder[$name] = 1;
            } else {
                $size = getimagesize('images/gallery/' . $verzeichnis . '/' . $name);
                $db->query('INSERT INTO ' . DB_PRE . 'ecp_gallery_images (`gID`, `filename`, `uploaded`, `userID`) VALUES (' . $id . ', \'' . strsave($name) . '\', ' . time() . ', ' . (int) $_SESSION['userID'] . ')');
                $pid = $db->last_id();
                $db->query('UPDATE ' . DB_PRE . 'ecp_gallery SET images = images + 1 WHERE galleryID= ' . $id);
                if ($size[0] > GALLERY_THUMB_SIZE) {
                    resize_picture('images/gallery/' . $verzeichnis . '/' . $name, GALLERY_THUMB_SIZE, 'images/gallery/' . $verzeichnis . '/thumbs/' . $pid . '_' . $name, 100);
                } else {
                    copy('images/gallery/' . $verzeichnis . '/' . $name, 'images/gallery/' . $verzeichnis . '/thumbs/' . $pid . '_' . $name);
                    umask(0);
                    chmod('images/gallery/' . $verzeichnis . '/thumbs/' . $pid . '_' . $name, CHMOD);
                }
                if ($size[0] > GALLERY_PIC_SIZE) {
                    resize_picture('images/gallery/' . $verzeichnis . '/' . $name, GALLERY_PIC_SIZE, 'images/gallery/' . $verzeichnis . '/' . $pid . '_' . $name, 100);
                    unlink('images/gallery/' . $verzeichnis . '/' . $name);
                } else {
                    rename('images/gallery/' . $verzeichnis . '/' . $name, 'images/gallery/' . $verzeichnis . '/' . $pid . '_' . $name);
                }
                $bilder[$name] = 1;
            }
        }
    }
    foreach ($bilder as $key => $value) {
        if ($value == 0) {
            if (file_exists('images/gallery/' . $verzeichnis . '/thumbs/' . $key)) {
                unlink('images/gallery/' . $verzeichnis . '/thumbs/' . $key);
            }
            $key = substr($key, strpos($key, '_') + 1);
            $pid = $db->result(DB_PRE . 'ecp_gallery_images', 'imageID', 'gID = ' . $id . ' AND filename = \'' . strsave($key) . '\'');
            $db->query('DELETE FROM ' . DB_PRE . 'ecp_gallery_images WHERE imageID=' . $pid);
            $db->query('DELETE FROM ' . DB_PRE . 'ecp_comments WHERE bereich = "gallery" AND subID = ' . $pid);
            $db->query('UPDATE ' . DB_PRE . 'ecp_gallery SET images = images - 1 WHERE galleryID=' . $id);
        }
    }
    header1('?section=admin&site=gallery&func=viewgallery&id=' . $id);
}