当前位置: 首页>>代码示例>>PHP>>正文


PHP REST::inputhandle方法代码示例

本文整理汇总了PHP中REST::inputhandle方法的典型用法代码示例。如果您正苦于以下问题:PHP REST::inputhandle方法的具体用法?PHP REST::inputhandle怎么用?PHP REST::inputhandle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在REST的用法示例。


在下文中一共展示了REST::inputhandle方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: inputhandle

 /**
  * Wrapper around fopen('php://input', 'r').
  * 
  * This wrapper is necessary to facilitate chunked transfer encoding and
  * method spoofing (in case PUT requests).
  * @return resource filehandle
  */
 public static function inputhandle()
 {
     if (self::$inputhandle === null) {
         if (isset($_SERVER['CONTENT_LENGTH'])) {
             self::$inputhandle = fopen('php://input', 'r');
         } elseif ($_SERVER['HTTP_TRANSFER_ENCODING'] == 'chunked') {
             self::$inputhandle = tmpfile();
             $input = fopen('php://input', 'r');
             while (!feof($input)) {
                 fwrite(self::$inputhandle, fgetc($input));
             }
             fclose($input);
             fseek(self::$inputhandle, 0);
         } else {
             self::fatal(self::HTTP_LENGTH_REQUIRED);
         }
     }
     return self::$inputhandle;
 }
开发者ID:pieterb,项目名称:REST,代码行数:26,代码来源:REST.php

示例2: elseif

        Topos::real_query("CALL `createTokens`({$escPool}, {$ntokens}, {$offset});");
        REST::fatal(REST::HTTP_ACCEPTED);
    } elseif (isset($_POST['tokens'])) {
        $input = tmpfile();
        fwrite($input, $_POST['tokens']);
        fseek($input, 0);
        $_SERVER['CONTENT_TYPE'] = 'text/plain; charset="UTF-8"';
    } else {
        REST::fatal(REST::HTTP_BAD_REQUEST);
    }
}
// Handle a upload of a single text file, of which each line will be a token.
if ($_SERVER['REQUEST_METHOD'] === 'POST' && strpos(@$_SERVER['CONTENT_TYPE'], 'text/') === 0) {
    $esccontenttype = Topos::escape_string($_SERVER['CONTENT_TYPE']);
    if (!$input) {
        $input = REST::inputhandle();
    }
    $stmt1 = Topos::mysqli()->prepare(<<<EOS
INSERT INTO `TokenValues` (
  `tokenValue`
) VALUES (?);
EOS
);
    $stmt2 = Topos::mysqli()->prepare(<<<EOS
INSERT INTO `Tokens` (
  `tokenId`, `poolId`, `tokenType`, `tokenLength`, `tokenCreated`
) VALUES (?, {$poolId}, {$esccontenttype}, ?, UNIX_TIMESTAMP());
EOS
);
    $bindTokenValue = $bindTokenId = $bindTokenLength = null;
    $stmt1->bind_param("s", $bindTokenValue);
开发者ID:sara-nl,项目名称:ToPoS,代码行数:31,代码来源:tokens.php

示例3: while

 */
require_once 'include/global.php';
require_once 'topos.php';
REST::require_method('GET', 'HEAD', 'PUT', 'DELETE');
$user_id = Portal_User::current()->user_id();
$path_info = Portal::path_info();
$jobid = $path_info[0];
$escjobid = Portal_MySQL::escape_string($jobid);
$escuserid = Portal_MySQL::escape_string($user_id);
if ($_SERVER['REQUEST_METHOD'] == 'PUT') {
    if (strpos(@$_SERVER['CONTENT_TYPE'], 'text/plain') !== 0) {
        REST::fatal(REST::HTTP_UNSUPPORTED_MEDIA_TYPE);
    }
    // The job finished with an error and tries to inform us about it
    $errorstring = '';
    while (($line = fread(REST::inputhandle(), 8192)) !== '') {
        $errorstring .= $line;
    }
    if (!strlen($errorstring)) {
        REST::fatal(REST::HTTP_BAD_REQUEST, 'No error string specified');
    }
    $errorstring = Portal_MySQL::escape_string($errorstring);
    Portal_MySQL::real_query(<<<EOS
UPDATE `Token` 
   SET `token_error` = CONCAT(`token_error`, {$errorstring})
 WHERE `token_id`={$escjobid}
   AND `user_id`={$escuserid};
EOS
);
    REST::header(array('status' => REST::HTTP_NO_CONTENT));
    exit;
开发者ID:CatchPlus,项目名称:CATCHPlus-Handle-Service,代码行数:31,代码来源:jobstate.php

示例4: tempnam

$user_id = Portal_User::current()->user_id();
$path_info = Portal::path_info();
$jobid = $path_info[0];
$escjobid = Portal_MySQL::escape_string($jobid);
$escuserid = Portal_MySQL::escape_string($user_id);
if ($_SERVER['REQUEST_METHOD'] == 'PUT') {
    if (strpos(@$_SERVER['CONTENT_TYPE'], 'application/x-compressed-tar') !== 0) {
        REST::fatal(REST::HTTP_UNSUPPORTED_MEDIA_TYPE);
    }
    // The job wants to put its results on the portal server
    $tmpfilename = tempnam('/tmp', 'portal_');
    $tmpfile = fopen($tmpfilename, 'w');
    while (($block = fread(REST::inputhandle(), 8192)) !== "") {
        fwrite($tmpfile, $block);
    }
    fclose(REST::inputhandle());
    fclose($tmpfile);
    if (isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['CONTENT_LENGTH'] != filesize($tmpfilename)) {
        unlink($tmpfilename);
        REST::fatal(REST::HTTP_BAD_REQUEST, "Content-Length header doesn't match actual content length.");
    }
    if (!rename($tmpfilename, Portal::JOBRESULTS_DIR . $jobid)) {
        unlink($tmpfilename);
        REST::fatal(REST::HTTP_INTERNAL_SERVER_ERROR, "Couldn't store uploaded file.");
    }
    chmod(Portal::JOBRESULTS_DIR . $jobid, 0660);
    REST::header(array('status' => REST::HTTP_NO_CONTENT));
    exit;
}
// The user tries to get information about his jobs
if (file_exists($fullfilename = Portal::JOBRESULTS_DIR . $jobid)) {
开发者ID:CatchPlus,项目名称:CATCHPlus-Handle-Service,代码行数:31,代码来源:jobresult.php

示例5: VALUES

 **************************************************************************/
require_once 'include/global.php';
$poolId = Topos::poolId($TOPOS_POOL);
if ($_SERVER['REQUEST_METHOD'] === 'PUT') {
    $tokenType = Topos::escape_string(empty($_SERVER['CONTENT_TYPE']) ? 'application/octet-stream' : $_SERVER['CONTENT_TYPE']);
    $tokenName = '';
    if (!empty($_SERVER['HTTP_CONTENT_DISPOSITION'])) {
        if (preg_match('/;\\s*filename\\s*=\\s*"((?:[^"\\\\]|\\\\.)+)"/', $_SERVER['HTTP_CONTENT_DISPOSITION'], $matches)) {
            $tokenName = $matches[1];
        }
    }
    $tokenName = Topos::escape_string($tokenName);
    $stmt = Topos::mysqli()->prepare('INSERT INTO `TokenValues` (`tokenValue`) VALUES (?);');
    $null = null;
    $stmt->bind_param("b", $null);
    $stream = REST::inputhandle();
    while (!feof($stream)) {
        $stmt->send_long_data(0, fread($stream, 8192));
    }
    fclose($stream);
    if (!$stmt->execute()) {
        REST::fatal(REST::HTTP_INTERNAL_SERVER_ERROR, $stmt->error);
    }
    $tokenId = Topos::mysqli()->insert_id;
    Topos::real_query(<<<EOS
INSERT INTO `Tokens`
       (`tokenId`, `poolId`, `tokenType`, `tokenName`, `tokenCreated`, `tokenLength`)
SELECT {$tokenId}, {$poolId}, {$tokenType}, {$tokenName},
       UNIX_TIMESTAMP(), LENGTH(`tokenValue`)
FROM `TokenValues`
WHERE `tokenId` = {$tokenId};
开发者ID:sara-nl,项目名称:ToPoS,代码行数:31,代码来源:nextToken.php


注:本文中的REST::inputhandle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。