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


PHP Response::setFileToSend方法代码示例

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


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

示例1: download

 public function download($id)
 {
     $anexo = Anexo::findFirst($id);
     $response = new Response();
     if ($anexo) {
         $response->setStatusCode(StatusCodes::OK);
         $response->setFileToSend($anexo->getCaminho(), $anexo->getOriginal());
     } else {
         $response->setStatusCode(StatusCodes::NAO_ENCONTRADO);
     }
     return $response;
 }
开发者ID:anderson-slompo,项目名称:wsGerProj,代码行数:12,代码来源:DownloadController.php

示例2: process

 /**
  * Выполняет все плагины по цепочке
  * 
  * @param \Phalcon\Http\Request $request
  * @return string
  */
 public function process(Request $request)
 {
     $response = new Response();
     $pluginResult = new PluginResult();
     foreach ($this->_arPlugins as $plugin) {
         $pluginResult = $plugin->process($request, $pluginResult);
         if ($pluginResult->terminate) {
             break;
         }
     }
     if ($pluginResult->error) {
         $response->setStatusCode($pluginResult->errorCode, $pluginResult->errorMessage);
         $response->setContent($pluginResult->errorMessage);
         return $response;
     } else {
         $response->setStatusCode(200, "OK");
     }
     $callback = $request->getQuery('callback');
     $result = '';
     if ($callback) {
         $response->setHeader('Content-Type', 'application/javascript');
         $result .= $callback . '(';
     } else {
         $response->setHeader('Content-Type', 'application/json');
     }
     $result .= json_encode(array('searchContext' => $pluginResult->searchContext, 'result' => $pluginResult->result));
     if ($callback) {
         $result .= ');';
     }
     if ($pluginResult->fileToSend) {
         $response->setFileToSend($pluginResult->fileToSend, 'data.txt');
     } else {
         $response->setContent($result);
     }
     return $response;
 }
开发者ID:olegabr,项目名称:kladrapi,代码行数:42,代码来源:ApiService.php

示例3: setFileToSend

 public function setFileToSend($filePath, $attachmentName = null, $attachment = true)
 {
     return parent::setFileToSend($filePath, $attachmentName, $attachment);
 }
开发者ID:mattvb91,项目名称:cphalcon,代码行数:4,代码来源:Response.php

示例4: download

 public function download($url, $destination = "", $file_name = "")
 {
     // check URL and get token if necessary
     preg_match("/(.*)periscope\\.tv\\/w\\/(.*)/", trim($url), $output_array);
     if (isset($output_array[2])) {
         $periscope_token = $output_array[2];
     } else {
         preg_match("/(.*)watchonperiscope\\.com\\/broadcast\\/(.*)/", trim($url), $output_array);
         if (isset($output_array[2])) {
             try {
                 $watchonperiscope_response = $this->_guzzle->get("https://watchonperiscope.com/api/accessChannel?broadcast_id=" . $output_array[2])->getBody();
             } catch (\GuzzleHttp\Exception\ServerException $e) {
                 throw new \Exception("URL error: Invalid watchonperiscope.com URL", 2);
             }
             $watchonperiscope_json = json_decode($watchonperiscope_response, true);
             if (!isset($watchonperiscope_json["error"])) {
                 preg_match("/(.*)periscope\\.tv\\/w\\/(.*)/", $watchonperiscope_json["share_url"], $output_array);
                 $periscope_token = $output_array[2];
             } else {
                 throw new \Exception("URL error: Invalid watchonperiscope.com URL", 2);
             }
         } else {
             throw new \Exception("URL error: Unsupported URL", 1);
         }
     }
     // construct filename and destination
     if ($file_name == "") {
         try {
             $periscope_details_response = $this->_guzzle->get("https://api.periscope.tv/api/v2/getBroadcastPublic?broadcast_id=" . $periscope_token)->getBody();
         } catch (\GuzzleHttp\Exception\ClientException $e) {
             throw new \Exception("Periscope error: Invalid token", 3);
         }
         $periscope_details_json = json_decode($periscope_details_response, true);
         $periscope_user = $periscope_details_json["user"]["username"];
         $periscope_start_time = $periscope_details_json["broadcast"]["start"];
         $date = substr($periscope_start_time, 0, 10);
         $hours = substr($periscope_start_time, 11, 2);
         $mins = substr($periscope_start_time, 14, 2);
         $file_name = $periscope_user . "_" . $date . "_" . $hours . "_" . $mins . ".ts";
     } else {
         $file_name = rtrim($file_name, ".ts") . ".ts";
     }
     if ($destination == "") {
         $destination = __DIR__ . "/";
     } else {
         $destination = rtrim($destination, "/") . "/";
     }
     // set up cookies
     try {
         $periscope_cookies_response = $this->_guzzle->get("https://api.periscope.tv/api/v2/getAccessPublic?broadcast_id=" . $periscope_token)->getBody();
     } catch (\GuzzleHttp\Exception\ClientException $e) {
         throw new \Exception("Periscope error: Invalid token", 3);
     }
     $periscope_cookies_json = json_decode($periscope_cookies_response, true);
     $replay_url = $periscope_cookies_json["replay_url"];
     $base_url = str_replace("/playlist.m3u8", "", $replay_url);
     $cookies = array();
     foreach ($periscope_cookies_json["cookies"] as $cookie) {
         $cookies[$cookie["Name"]] = $cookie["Value"];
     }
     $cookie_jar = new \GuzzleHttp\Cookie\CookieJar();
     $periscope_cookies = $cookie_jar::fromArray($cookies, "replay.periscope.tv");
     // download playlist and all chunks
     $periscope_playlist_response = $this->_guzzle->get($replay_url, ["cookies" => $periscope_cookies])->getBody()->getContents();
     preg_match_all("/chunk_(.*)\\.ts/", $periscope_playlist_response, $chunk_array);
     $tmp_folder = $destination . "/" . bin2hex(openssl_random_pseudo_bytes(16)) . "/";
     shell_exec("mkdir " . $tmp_folder);
     $path = $destination . $file_name;
     if (!file_exists($path)) {
         shell_exec("cat " . $tmp_folder . $chunk_array[0][0] . " >> " . $path);
     }
     $response = new Response();
     $filetype = filetype($path);
     $filesize = filesize($path);
     while (ob_get_level()) {
         ob_end_clean();
     }
     $response->setHeader("Content-Description", 'File Transfer');
     $response->setHeader("Cache-Control", 'must-revalidate, post-check=0, pre-check=0');
     $response->setHeader("Content-Disposition", 'attachment; filename=' . $file_name);
     $response->setHeader("Content-Type", $filetype);
     $response->setHeader("Content-Length", $filesize);
     $response->setHeader("Content-Transfer-Encoding", 'binary');
     $response->setHeader("Expires", '0');
     $response->setHeader("Pragma", 'public');
     $response->setFileToSend($path, null, false);
     $response->send();
     foreach ($chunk_array[0] as $chunk) {
         $chunk_response = $this->_guzzle->get($base_url . "/" . $chunk, ["cookies" => $periscope_cookies])->getBody()->getContents();
         //, 'stream' => true
         //               $chunk_size = $chunk_response->getHeader('content-length');
         //               $body = $chunk_response->getBody();
         //
         //                while ( ! $body->eof()) {
         //                    echo $body->read($chunk_size[0]);
         //                }
         file_put_contents($tmp_folder . $chunk, $chunk_response);
         $chunk_size = filesize($tmp_folder . $chunk);
         if (file_exists($path)) {
             shell_exec("cat " . $path . ' ' . $tmp_folder . $chunk . " >> " . $path);
//.........这里部分代码省略.........
开发者ID:sinbad13,项目名称:periscope-downloader,代码行数:101,代码来源:PeriscopeDownloader.php


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