Example #1
0
 /**
  * 文件上传
  */
 function upload()
 {
     $upload_dir = ROOT_PATH . 'data/uploads/';
     $allowed_ext = array('jpg', 'jpeg', 'png', 'gif');
     if (strtolower($_SERVER['REQUEST_METHOD']) != 'post') {
         exit_status('Error! Wrong HTTP method!');
     }
     if (array_key_exists('pic', $_FILES) && $_FILES['pic']['error'] == 0) {
         $pic = $_FILES['pic'];
         $pic_name = $pic['name'];
         $ext = $this->get_extension($pic_name);
         if (!in_array($ext, $allowed_ext)) {
             exit_status('Only ' . implode(',', $allowed_ext) . ' files are allowed!');
         }
         // Move the uploaded file from the temporary
         // directory to the uploads folder:
         $tmpfilename = $pic['tmp_name'];
         $filename = $upload_dir . $pic['name'];
         if (move_uploaded_file($tmpfilename, $filename)) {
             $this->out_json(true, 'File was uploaded successfuly!', array('fileName' => $pic['name']));
         }
     }
     $this->out_json(false, 'Something went wrong with your upload!');
 }
Example #2
0
    //设定要用于合成的三张图片(如果重叠,排在后面的图片会盖住排在前面的图片)
    $img->setData(array(array($new_data, 0, 0, 1, SAE_TOP_LEFT), array($logo_ten_year_img, -10, 10, 1, SAE_BOTTOM_RIGHT), array($logo_zfb_img, -10, -10, 1, SAE_TOP_RIGHT), array($text_bg_img, 0, -47, 1, SAE_TOP_LEFT)));
    //执行合成
    $img->composite($size[0], $size[1]);
    //输出图片
    $new_data = $img->exec('jpg');
    if ($new_data === false) {
        exit_status('error', 'p2:' . $img->errmsg());
    }
    $s = new SaeStorage();
    $result = $s->write('rank', $file_name, $new_data);
    if (!$result) {
        exit_status('fail', $result);
    }
    $url = $s->getUrl('rank', $file_name);
    exit_status('ok', $url);
} else {
    exit_status('fail', 'no file accept!');
}
// Helper functions
function exit_status($status, $data)
{
    echo json_encode(array('status' => $status, 'data' => $data));
    exit;
}
function get_extension($file_name)
{
    $ext = explode('.', $file_name);
    $ext = array_pop($ext);
    return strtolower($ext);
}
Example #3
0
<?php

session_start();
if (strtolower($_SERVER['REQUEST_METHOD']) != 'post') {
    exit_status('Error! Wrong HTTP method!');
}
if (!isset($_SESSION['user'])) {
    exit(json_encode(array('status' => "Unauthorized access")));
}
if (isset($_POST['liteUploader_id']) && $_POST['liteUploader_id'] == 'postfiles') {
    foreach ($_FILES['postfiles']['error'] as $key => $error) {
        if ($error == UPLOAD_ERR_OK) {
            move_uploaded_file($_FILES['postfiles']['tmp_name'][$key], '../../posts/' . $_FILES['postfiles']['name'][$key]);
        }
    }
    echo '<span class="success"></span>';
}
Example #4
0
// If you want to ignore the uploaded files,
// set $demo_mode to true;
$upload_dir = 'content/';
$allowed_ext = array('jpg', 'jpeg', 'png', 'gif', '.tiff', '.cr2');
if (strtolower($_SERVER['REQUEST_METHOD']) != 'post') {
    exit_status('Error! Wrong HTTP method!');
}
if (array_key_exists('pic', $_FILES) && $_FILES['pic']['error'] == 0) {
    $pic = $_FILES['pic'];
    if (!in_array(get_extension($pic['name']), $allowed_ext)) {
        exit_status('Only ' . implode(',', $allowed_ext) . ' files are allowed!');
    }
    // Move the uploaded file from the temporary
    // directory to the uploads folder:
    if (move_uploaded_file($pic['tmp_name'], $upload_dir . $pic['name'])) {
        exit_status('File was uploaded successfuly!');
    }
}
exit_status('Something went wrong with your upload!');
// Helper functions
function exit_status($str)
{
    echo json_encode(array('status' => $str));
    exit;
}
function get_extension($file_name)
{
    $ext = explode('.', $file_name);
    $ext = array_pop($ext);
    return strtolower($ext);
}
Example #5
0
require "../../../../wp-load.php";
if (!function_exists("wp_create_thumbnail")) {
    require '../../../../wp-admin/includes/image.php';
}
if (empty($_POST["id"]) || !is_user_logged_in() || !is_numeric($_POST["id"])) {
    exit;
}
/*CHECK USER IS ALLOUD TO INTERACT WITH THIS item
 *
 *
 *
 */
global $wpdb, $bp;
// Helper functions
$current_user = wp_get_current_user();
$user_id = $current_user->ID;
$yours = $wpdb->get_row("SELECT * FROM " . $wpdb->prefix . BEPRO_LISTINGS_TABLE_NAME . " WHERE user_id = {$user_id} AND id = " . $_POST["id"]);
if (!$yours) {
    exit;
}
function exit_status($str)
{
    echo json_encode(array('status' => $str));
    exit;
}
if (wp_delete_post($yours->post_id)) {
    exit_status('Deleted Successfully!');
}
exit_status('Something went wrong with your Delete!');
 public function actionSweImageUpload()
 {
     $demo_mode = false;
     $upload_dir = 'upload/';
     $allowed_ext = array('jpg', 'jpeg', 'png', 'gif');
     if (strtolower($_SERVER['REQUEST_METHOD']) != 'post') {
         exit_status('Error! Wrong HTTP method!');
     }
     if (array_key_exists('pic', $_FILES) && $_FILES['pic']['error'] == 0) {
         $pic = $_FILES['pic'];
         if (!in_array(pathinfo($pic['name'], PATHINFO_EXTENSION), $allowed_ext)) {
             exit_status('Only ' . implode(',', $allowed_ext) . ' files are allowed!');
         }
         if ($demo_mode) {
             // File uploads are ignored. We only log them.
             $line = implode('		', array(date('r'), $_SERVER['REMOTE_ADDR'], $pic['size'], $pic['name']));
             file_put_contents('log.txt', $line . PHP_EOL, FILE_APPEND);
             exit_status('Uploads are ignored in demo mode.');
         }
         // Move the uploaded file from the temporary
         // directory to the uploads folder:
         if (move_uploaded_file($pic['tmp_name'], $upload_dir . $pic['name'])) {
             exit_status('File was uploaded successfuly!');
         }
     }
     exit_status('Something went wrong with your upload!');
 }
<?php

$upload_dir = 'uploads/';
$allowed_ext = array('jpg', 'jpeg', 'png', 'gif');
if (array_key_exists('pic', $_FILES) && $_FILES['pix']['error'] == 0) {
    $pic = $_FILES['pic'];
    if (!in_array(get_extension($pic['name']), $allowed_ext)) {
        exit_status('Only ' . implode(',', $allowed_ext) . ' files are allowed');
    }
    if (move_uploaded_file($pic['tmp_name'], $upload_dir . $pic['name'])) {
        exit_status('Your file was uploaded');
    }
}
// Helpers
function exit_status($str)
{
    echo json_encode(array('status' => $str));
    exit;
}
function get_extension($file)
{
    $ext = explode('.', $file);
    $ext = array_pop($ext);
    return strtolower($ext);
}
Example #8
0
<?php

$upload_dir = 'uploads/';
$allowed_ext = array('jpg', 'jpeg', 'png', 'gif');
if (array_key_exists('pic', $_FILES) && $_FILES['pic']['error'] == 0) {
    $pic = $_FILES['pic'];
    if (!in_array(get_extension($pic['name']), $allowed_ext)) {
        exit_status('Only ' . implode(',', $allowed_ext) . ' files are allowed');
    }
    if (move_uploaded_file($pic['tmp_name'], $upload_dir . $pic['name'])) {
        exit_status('File uploaded');
    }
}
//Helpers
function exit_status($str)
{
    echo json_encode(array('status' => $str));
    exit;
}
function get_extension($file)
{
    $ext = explode('.', $file);
    $ext = array_pop($ext);
    return strtolower($ext);
}
Example #9
0
function uploadContent()
{
    $upload_dir = $siteRoot . 'uploads/';
    $allowed_ext = array('jpg', 'jpeg', 'JPG', 'JPEG', 'png', 'PNG', 'gif', 'GIF');
    $all_thumbs = json_decode(@file_get_contents($siteRoot . 'pages/all_pics.json'), true);
    if (strtolower($_SERVER['REQUEST_METHOD']) != 'post') {
        exit_status('Error! Wrong HTTP method!');
    }
    if (array_key_exists('pic', $_FILES) && $_FILES['pic']['error'] == 0) {
        $pic = $_FILES['pic'];
        $picNameFix = array("+", "(", ")", "|", "'", "?", " ");
        $picName = str_replace($picNameFix, '', $pic['name']);
        if (!in_array(get_extension($picName), $allowed_ext)) {
            exit_status('Only ' . implode(',', $allowed_ext) . ' files are allowed!');
        }
        // Ensure that file name is unique
        if ($all_thumbs[$picName]) {
            for ($i = 1; $i <= 20; $i++) {
                if ($all_thumbs[$i . '_' . $picName]) {
                } else {
                    $picName = $i . '_' . $picName;
                    break;
                }
            }
        }
        // Move the uploaded file from the temporary directory to the uploads folder,
        // create a thumbnail, and log all pics in json file:
        if (move_uploaded_file($pic['tmp_name'], $upload_dir . $picName)) {
            setContent($picName, $upload_dir . $picName, 'all_pics');
            $type = false;
            function open_image($file)
            {
                //detect type and process accordinally
                global $type;
                $size = getimagesize($file);
                switch ($size["mime"]) {
                    case "image/jpeg":
                        $im = imagecreatefromjpeg($file);
                        //jpeg file
                        break;
                    case "image/gif":
                        $im = imagecreatefromgif($file);
                        //gif file
                        break;
                    case "image/png":
                        $im = imagecreatefrompng($file);
                        //png file
                        break;
                    default:
                        $im = false;
                        break;
                }
                return $im;
            }
            $thumbnailImage = open_image($upload_dir . $picName);
            $w = imagesx($thumbnailImage);
            $h = imagesy($thumbnailImage);
            //calculate new image dimensions (preserve aspect)
            if (isset($_GET['w']) && !isset($_GET['h'])) {
                $new_w = $_GET['w'];
                $new_h = $new_w * ($h / $w);
            } elseif (isset($_GET['h']) && !isset($_GET['w'])) {
                $new_h = $_GET['h'];
                $new_w = $new_h * ($w / $h);
            } else {
                $new_w = isset($_GET['w']) ? $_GET['w'] : 60;
                $new_h = isset($_GET['h']) ? $_GET['h'] : 60;
                if ($w / $h > $new_w / $new_h) {
                    $new_h = $new_w * ($h / $w);
                } else {
                    $new_w = $new_h * ($w / $h);
                }
            }
            $im2 = ImageCreateTrueColor($new_w, $new_h);
            $imageFormat = strtolower(substr(strrchr($picName, "."), 1));
            if ($imageFormat == "gif" || $imageFormat == "png") {
                imagecolortransparent($im2, imagecolorallocatealpha($im2, 0, 0, 0, 127));
                imagealphablending($im2, false);
                imagesavealpha($im2, true);
            }
            imagecopyResampled($im2, $thumbnailImage, 0, 0, 0, 0, $new_w, $new_h, $w, $h);
            //effects
            if (isset($_GET['blur'])) {
                $lv = $_GET['blur'];
                for ($i = 0; $i < $lv; $i++) {
                    $matrix = array(array(1, 1, 1), array(1, 1, 1), array(1, 1, 1));
                    $divisor = 9;
                    $offset = 0;
                    imageconvolution($im2, $matrix, $divisor, $offset);
                }
            }
            if (isset($_GET['sharpen'])) {
                $lv = $_GET['sharpen'];
                for ($i = 0; $i < $lv; $i++) {
                    $matrix = array(array(-1, -1, -1), array(-1, 16, -1), array(-1, -1, -1));
                    $divisor = 8;
                    $offset = 0;
                    imageconvolution($im2, $matrix, $divisor, $offset);
                }
            }
            imagejpeg($im2, $upload_dir . 'thumbs/' . $picName);
            imagegif($im2, $upload_dir . 'thumbs/' . $picName);
            imagepng($im2, $upload_dir . 'thumbs/' . $picName);
            //move_uploaded_file($thumbnailImage, $upload_dir.'thumbs/'.$picName);
            //copy($upload_dir.$picName, $upload_dir.'thumbs/'.$picName);
            exit_status('File was uploaded successfuly!');
        }
    }
    exit_status('Something went wrong with your upload!');
}
Example #10
0
<?php

header('Content-type:text/html; charset="utf-8"');
error_reporting(0);
$upload_dir = 'uploads/';
if (strtolower($_SERVER['REQUEST_METHOD']) != 'post') {
    exit_status(array('code' => 1, 'msg' => '错误提交方式'));
}
if (array_key_exists('file', $_FILES) && $_FILES['file']['error'] == 0) {
    $pic = $_FILES['file'];
    if (move_uploaded_file($pic['tmp_name'], $upload_dir . $pic['name'])) {
        exit_status(array('code' => 0, 'msg' => '上传成功', 'url' => $upload_dir . $pic['name']));
    }
}
echo $_FILES['file']['error'];
exit_status(array('code' => 1, 'msg' => '出现了一些错误'));
function exit_status($str)
{
    echo json_encode($str);
    exit;
}
Example #11
0
        $ext = get_extension($_FILES['file']['name']);
        $newName = $newImageNameAndId;
        rename('' . $albumURL . '' . $_FILES['file']['name'], '' . $albumURL . '' . $newName . '.' . $ext);
        if ($ext !== $convetimageTo) {
            convertImage($albumURL . $newName . '.' . $ext, $albumURL . $newName . '.' . $convetimageTo, 100);
            unlink($albumURL . $newName . '.' . $ext);
            $ext = $convetimageTo;
        }
        $width = $cropImagesWidth;
        $Thumb = $albumURL . $newName . '.' . $ext;
        $imageFileType = pathinfo($Thumb, PATHINFO_EXTENSION);
        $imageFile = $Thumb;
        $info = getimagesize($imageFile);
        if ($info[0] >= $cropImagesWidth) {
            include 'tinyImage.php';
            $aspectRatio = $info[1] / $info[0];
            $newHeight = (int) ($aspectRatio * $width);
            $image = new SimpleImage();
            $image->load($Thumb);
            $image->resize($width, $newHeight);
            $image->save($Thumb);
        }
        $info = getimagesize($imageFile);
        echo addToDb($_FILES['file']['name'], $info[0] . ':' . $info[1], $ext, $newName . '.' . $ext, $imagePath . $newName . '.' . $ext);
        //echo $imagePath.$newName.'.'.$ext;
    } else {
        echo exit_status('Move failed');
    }
} else {
    echo exit_status('No files');
}
Example #12
0
<?php

$diretorio = "./uploads/";
$arq_perm = array('jpg', 'jpeg', 'png', 'gif');
if (strtolower($_SERVER['REQUEST_METHOD']) != 'post') {
    exit_status('Erro! Método HTTP errado!');
}
if (array_key_exists('pic', $_FILES) && $_FILES['pic']['error'] == 0) {
    $imagem = $_FILES['pic'];
    if (!in_array(get_extension($imagem['name']), $arq_perm)) {
        exit_status('Apenas arquivos dos tipos ' . implode(',', $arq_perm) . ' são permitidos!');
    }
    if (move_uploaded_file($imagem['tmp_name'], $diretorio . $imagem['name'])) {
        exit_status('Upload concluído com sucesso!');
    }
}
exit_status('Aconteceu algum problema com o upload!');
function exit_status($str)
{
    echo json_encode(array('status' => $str));
    exit;
}
function get_extension($file_name)
{
    $ext = explode('.', $file_name);
    $ext = array_pop($ext);
    return strtolower($ext);
}
Example #13
0
<?php

$upload_dir = 'uploads/*';
$allowed_ext = array('jpg', 'jpeg', 'png', 'gif');
if (array_key_exists('pic', $_FILES) && $_FILES['pic']['error'] == 0) {
    $pic = $_FILES['pic'];
}
if (!in_array(get_extension($pic['name']), $allowed_ext)) {
    exit_status('Only ' . implode(',', $allowed_ext) . ' files are allowed');
}
if (move_uploaded_file($pic['tmp_name'], $upload_dir . $pic['name'])) {
    exit_status('The file was uploaded');
}
//Helpers
function exit_status($str)
{
    echo json_encode(array('status' => $str));
    exit;
}
function get_extension($file)
{
    $ext = explode(".", $file);
    $ext = array_pop($ext);
    return strtolower($ext);
}
                $t_result[0]['size'] = strlen($data);
                $t_result[0]['tmp_name'] = $fn;
                $t_result[0]['error'] = 0;
            }
        } else {
            if (func_num_args() > 1) {
                # check for a default passed in (allowing null)
                $t_result = $p_default;
            } else {
                error_parameters($p_var_name);
                trigger_error(ERROR_GPC_VAR_NOT_FOUND, ERROR);
            }
        }
    }
    return $t_result;
}
$f_bug_id = gpc_get_int('bug_id', -1);
$f_files = gpc_get_fileCustom('pic', -1);
if ($f_bug_id == -1 && $f_files == -1) {
    # _POST/_FILES does not seem to get populated if you exceed size limit so check if bug_id is -1
    trigger_error(ERROR_FILE_TOO_BIG, ERROR);
}
$t_bug = bug_get($f_bug_id, true);
if (!file_allow_bug_upload($f_bug_id)) {
    access_denied();
}
access_ensure_bug_level(config_get('upload_bug_file_threshold'), $f_bug_id);
file_add($f_bug_id, $f_files, 'bug', '', '', 1);
#Message de succès d'envoi
exit_status(plugin_lang_get('file_was_uploaded_successfuly'));