コード例 #1
0
ファイル: index.php プロジェクト: rwadholm/encounters
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!');
}
コード例 #2
0
ファイル: ajax.php プロジェクト: aofrozen/angular-php-sample
        if ($notification) {
            $app->response->setJsonContent(array("friends" => array('addFriendButtonName' => 'Add Friend'), 'alerts' => array('type' => 'warning', 'message' => 'User already sent a friend request. Check your notifications.')));
            $app->response->send();
        } else {
            if ((new notifications())->_create($data->fid, 'friend.request', $uid, array(''))) {
                $app->response->setJsonContent(array("friends" => array('addFriendButtonName' => 'Friend Request Sent')));
                $app->response->send();
            } else {
                //failed to add
                $app->response->setJsonContent(array("friends" => array('addFriendButtonName' => 'Friend Request Sent'), 'alerts' => array('type' => 'danger', 'message' => 'Not able to send a friend request. Try it again later.')));
                $app->response->send();
            }
        }
    } else {
        //Already Friend then unfriend
        $app->response-- > setContent(json_encode(array("friends" => array('addFriendButtonName' => 'Friends'), 'alerts' => array('type' => 'danger', 'message' => 'Not able to send a friend request. Try it again later.')), JSON_PRETTY_PRINT));
        $app->response->send();
    }
});
$app->delete('/ajax/friends', function () use($app) {
    $uid = (new userSessions())->requiredLogin(true);
    $data = $app->request->getJsonRawBody();
    if (!isset($data->fid)) {
        return false;
    }
    if ((new friends())->_delete($uid, $data->fid) && (new friends())->_delete($data->fid, $uid)) {
        (new feedfollows())->_delete($uid, $data->fid);
        (new feedfollows())->_delete($data->fid, $uid);
        (new metafriends())->_updateFriendCount($uid, $data->fid, -1);
    }
    $app->response->setContent(json_encode(array("friends" => array('addFriendButtonName' => 'Add Friend')), JSON_PRETTY_PRINT));
コード例 #3
0
            include LINK_PAGE_ERR_400;
        } else {
            if ($_GET["content"] == ERROR_401) {
                include LINK_PAGE_ERR_401;
            } else {
                if ($_GET["content"] == ERROR_403) {
                    include LINK_PAGE_ERR_403;
                } else {
                    if ($_GET["content"] == ERROR_404) {
                        include LINK_PAGE_ERR_404;
                    } else {
                        if ($_GET["content"] == ERROR_500) {
                            include LINK_PAGE_ERR_500;
                        } else {
                            // Set content
                            setContent();
                        }
                    }
                }
            }
        }
    }
}
?>
        </div>

        <!-- AddThis div (test) -->
        <div id="addThis">
          <!-- AddThis Button BEGIN -->
          <div class="addthis_toolbox addthis_default_style">
            <a class="addthis_button_google_plusone"></a>
コード例 #4
0
                $savePath = 'http://' . getServerIp() . '/uploads/recommendedfood/' . $res1['savename'];
                $savePath = stringToDb($savePath);
                $imagefile[] = $savePath;
            } else {
                //上传图片失败
                echo getJsonResponse(4, $uf->errorMsg, null);
                $db->rollback();
                //回滚
                $db->close();
                exit;
            }
        }
    }
    //做法步骤
    if (isset($_POST['content'])) {
        setContent($db, $recid, $_POST['content'], $imagefile);
    }
    $db->commit();
    echo getJsonResponse(0, 'success', $rec[0]['recommend_id']);
    $db->close();
} else {
    echo getJsonResponse(2, "参数没有设置", null);
    exit;
}
/**
 * 检查是否有这食物
 * @param DB $db
 * @param string $foodname
 * @return int
 */
function checkFoodname(&$db, $foodname, &$flag)