Esempio n. 1
0
function upload_images()
{
    global $user, $MSG;
    if (!$user->logged_in) {
        // imitate code execution
        die(json_encode(array('OK' => 0, 'error' => array('code' => '202', 'message' => $MSG['login_required_text']))));
    } else {
        global $main_path, $upload_path, $include_path;
        require_once $include_path . "PluploadHandler.php";
        $uploader = new PluploadHandler();
        $uploader->no_cache_headers();
        $uploader->cors_headers();
        $targetDir = $upload_path . session_id();
        if (!$uploader->handle(array('target_dir' => $targetDir, 'allow_extensions' => 'jpg,jpeg,png,gif'))) {
            die(json_encode(array('OK' => 0, 'error' => array('code' => $uploader->get_error_code(), 'message' => $uploader->get_error_message()))));
        } else {
            //upload was good
            $conf = $uploader->get_conf();
            $fileName = $conf['file_name'];
            if (!in_array($fileName, $_SESSION['UPLOADED_PICTURES'])) {
                $final_file_name = strtolower($fileName);
                array_push($_SESSION['UPLOADED_PICTURES'], $final_file_name);
                if (count($_SESSION['UPLOADED_PICTURES']) == 1) {
                    $_SESSION['SELL_pict_url_temp'] = $_SESSION['SELL_pict_url'] = $final_file_name;
                }
            }
            die(json_encode(array('OK' => 1)));
        }
    }
}
Esempio n. 2
0
function upload_images()
{
    global $user, $MSG, $system;
    if (!$user->logged_in) {
        // imitate code execution
        die(json_encode(array('OK' => 0, 'error' => array('code' => '202', 'message' => $MSG['login_required_text']))));
    } else {
        require_once PACKAGE_PATH . 'PluploadHandler.php';
        $uploader = new PluploadHandler();
        $uploader->no_cache_headers();
        $uploader->cors_headers();
        $targetDir = UPLOAD_PATH . session_id();
        if (!$uploader->handle(array('target_dir' => $targetDir, 'allow_extensions' => 'jpg,jpeg,png,gif'))) {
            die(json_encode(array('OK' => 0, 'error' => array('code' => $uploader->get_error_code(), 'message' => $uploader->get_error_message()))));
        } else {
            //upload was good
            $conf = $uploader->get_conf();
            $fileName = $conf['file_name'];
            // resize picture
            $uploader->resizeThumbnailImage($targetDir . '/' . $fileName, $system->SETTINGS['gallery_max_width_height']);
            $final_file_name = strtolower($fileName);
            if (!in_array($final_file_name, $_SESSION['UPLOADED_PICTURES'])) {
                array_push($_SESSION['UPLOADED_PICTURES'], $final_file_name);
                if (count($_SESSION['UPLOADED_PICTURES']) == 1) {
                    $_SESSION['SELL_pict_url_temp'] = $_SESSION['SELL_pict_url'] = $final_file_name;
                }
            }
            die(json_encode(array('OK' => 1)));
        }
    }
}