Example #1
0
                } else {
                    if (!underPath($file)) {
                        $return['error'] = true;
                        $return['errorText'][$db_name] = 'is not in your image path';
                    } else {
                        if (!rename($file, $destination)) {
                            $return['error'] = true;
                            $return['errorText'][$db_name] = 'could not be deleted';
                        } else {
                            if ($ext == 'jpg') {
                                // delete database entry if it is an image
                                //$q = new myQuery("SELECT id FROM img WHERE name='{$db_name}'");
                                //$id = $q->get_one();
                                $q = new myQuery("DELETE FROM img WHERE name='{$db_name}'");
                                if ($q->get_affected_rows() != 1) {
                                    //$return['error'] = true;
                                    $return['errorText'][$db_name] = 'deleted (not from db)';
                                } else {
                                    $return['errorText'][$db_name] = 'deleted';
                                }
                                //$q = new myQuery("DELETE FROM tag WHERE id='{$id}'");
                            }
                        }
                    }
                }
            }
        }
    }
}
scriptReturn($return);
exit;
Example #2
0
<?php

require_once $_SERVER['DOCUMENT_ROOT'] . '/include/main_func.php';
auth();
$return = array('error' => false, 'errorText' => '');
// register logout
$q = new myQuery("UPDATE login SET logouttime=NOW() WHERE user_id='{$_SESSION['user_id']}' \n                    AND logouttime IS NULL ORDER BY logintime DESC LIMIT 1");
// remove any persistent cookies
setcookie('user_id', '', time() + 60 * 60 * 24 * 365, '/', $_SERVER['SERVER_NAME']);
setcookie('id_hash', '', time() + 60 * 60 * 24 * 365, '/', $_SERVER['SERVER_NAME']);
//setcookie('email',   '', time()+60*60*24*365, '/', $_SERVER['SERVER_NAME']);
session_destroy();
scriptReturn($return, true);
// don't wait for tmp dir emptying
require_once $_SERVER['DOCUMENT_ROOT'] . '/scripts/dirTmpEmpty.php';
Example #3
0
//检查是否是正常文件
if ($_FILES["upload"]["error"] > 0) {
    scriptReturn('', '未选择文件', 422);
}
//图片大小不能超过4M,像素宽高不能超过4000
if (filesize($_FILES['upload']['tmp_name']) > 4 * 1024 * 1024) {
    scriptReturn('', '图片大小不能超过4M', 422);
}
$imageInfo = getimagesize($_FILES['upload']['tmp_name']);
if (!$imageInfo || $imageInfo[0] > 4000 || $imageInfo[1] > 4000) {
    scriptReturn('', '图片像素宽高不能超过4000', 422);
}
//上传处理
$fileExt = pathinfo($_FILES['upload']['name'], PATHINFO_EXTENSION);
$target = UPLOAD_DIR . "/" . basename($_FILES['upload']['tmp_name']) . ".{$fileExt}";
//如果需要裁剪图片则裁剪,不需要直接保存
if (isset($_POST['x']) && isset($_POST['y']) && !empty($_POST['w']) && !empty($_POST['h']) && !empty($_POST['iw'])) {
    cropImage($target, $_FILES['upload']['tmp_name'], $_POST['x'], $_POST['y'], $_POST['w'], $_POST['h'], $_POST['iw']);
} else {
    move_uploaded_file($_FILES['upload']['tmp_name'], $target);
}
//传文件
$post_data = array('upload' => "@{$target}");
$uploadUrl = "http://api.grocery.pptv.com/upload_file.php?app={$_GET['app']}&tk={$_GET['tk']}&prod={$_GET['prod']}";
$return = json_decode(send_post_pic($uploadUrl, $post_data), 1);
@unlink($target);
if (empty($return['data'])) {
    scriptReturn('', '公有云接口出错', 500);
}
scriptReturn($return['data'], 'success', 0);
Example #4
0
function checkAllocation()
{
    // check permissions for this project
    $q = new myQuery("SELECT perm\n                          FROM project_user\n                          WHERE user_id='{$_SESSION['user_id']}'\n                            AND project_id='{$_SESSION['project_id']}'");
    $perm = $q->get_one();
    if ($perm !== 'all') {
        $return = array("error" => true, "errorText" => "You do not have permission to save files to this project.");
        scriptReturn($return);
        exit;
    }
    // check overall allocation
    $ua = userAllocation($_SESSION['user_id']);
    if ($ua['size'] > $ua['allocation']) {
        $return = array("error" => true, "size" => $ua['size'], "allocation" => $ua['allocation'], "errorText" => "You have exceeded your allocation of " . round($ua['allocation'] / 1024, 1) . " GB");
        scriptReturn($return);
        exit;
    }
    // return true if all fine
    return true;
}