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


PHP OC_Filesystem::readfile方法代码示例

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


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

示例1: get

 /**
  * return the content of a file or return a zip file containning multiply files
  *
  * @param dir  $dir
  * @param file $file ; seperated list of files to download
  * @param boolean $only_header ; boolean to only send header of the request
  */
 public static function get($dir, $files, $only_header = false)
 {
     if (strpos($files, ';')) {
         $files = explode(';', $files);
     }
     if (is_array($files)) {
         self::validateZipDownload($dir, $files);
         $executionTime = intval(ini_get('max_execution_time'));
         set_time_limit(0);
         $zip = new ZipArchive();
         $filename = OC_Helper::tmpFile('.zip');
         if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== TRUE) {
             exit("cannot open <{$filename}>\n");
         }
         foreach ($files as $file) {
             $file = $dir . '/' . $file;
             if (OC_Filesystem::is_file($file)) {
                 $tmpFile = OC_Filesystem::toTmpFile($file);
                 self::$tmpFiles[] = $tmpFile;
                 $zip->addFile($tmpFile, basename($file));
             } elseif (OC_Filesystem::is_dir($file)) {
                 self::zipAddDir($file, $zip);
             }
         }
         $zip->close();
         set_time_limit($executionTime);
     } elseif (OC_Filesystem::is_dir($dir . '/' . $files)) {
         self::validateZipDownload($dir, $files);
         $executionTime = intval(ini_get('max_execution_time'));
         set_time_limit(0);
         $zip = new ZipArchive();
         $filename = OC_Helper::tmpFile('.zip');
         if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== TRUE) {
             exit("cannot open <{$filename}>\n");
         }
         $file = $dir . '/' . $files;
         self::zipAddDir($file, $zip);
         $zip->close();
         set_time_limit($executionTime);
     } else {
         $zip = false;
         $filename = $dir . '/' . $files;
     }
     @ob_end_clean();
     if ($zip or OC_Filesystem::is_readable($filename)) {
         header('Content-Disposition: attachment; filename="' . basename($filename) . '"');
         header('Content-Transfer-Encoding: binary');
         OC_Response::disableCaching();
         if ($zip) {
             ini_set('zlib.output_compression', 'off');
             header('Content-Type: application/zip');
             header('Content-Length: ' . filesize($filename));
         } else {
             $fileData = OC_FileCache::get($filename);
             header('Content-Type: ' . $fileData['mimetype']);
         }
     } elseif ($zip or !OC_Filesystem::file_exists($filename)) {
         header("HTTP/1.0 404 Not Found");
         $tmpl = new OC_Template('', '404', 'guest');
         $tmpl->assign('file', $filename);
         $tmpl->printPage();
     } else {
         header("HTTP/1.0 403 Forbidden");
         die('403 Forbidden');
     }
     if ($only_header) {
         if (!$zip) {
             header("Content-Length: " . OC_Filesystem::filesize($filename));
         }
         return;
     }
     if ($zip) {
         $handle = fopen($filename, 'r');
         if ($handle) {
             $chunkSize = 8 * 1024;
             // 1 MB chunks
             while (!feof($handle)) {
                 echo fread($handle, $chunkSize);
                 flush();
             }
         }
         unlink($filename);
     } else {
         OC_Filesystem::readfile($filename);
     }
     foreach (self::$tmpFiles as $tmpFile) {
         if (file_exists($tmpFile) and is_file($tmpFile)) {
             unlink($tmpFile);
         }
     }
 }
开发者ID:jaeindia,项目名称:ownCloud-Enhancements,代码行数:98,代码来源:files.php

示例2: header

* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library.  If not, see <http://www.gnu.org/licenses/>.
*
*/
// Init owncloud
// Check if we are a user
OCP\User::checkLoggedIn();
$filename = $_GET["file"];
if (!OC_Filesystem::file_exists($filename)) {
    header("HTTP/1.0 404 Not Found");
    $tmpl = new OCP\Template('', '404', 'guest');
    $tmpl->assign('file', $filename);
    $tmpl->printPage();
    exit;
}
$ftype = OC_Filesystem::getMimeType($filename);
header('Content-Type:' . $ftype);
header('Content-Disposition: attachment; filename="' . basename($filename) . '"');
OCP\Response::disableCaching();
header('Content-Length: ' . OC_Filesystem::filesize($filename));
@ob_end_clean();
OC_Filesystem::readfile($filename);
开发者ID:jaeindia,项目名称:ownCloud-Enhancements,代码行数:30,代码来源:download.php

示例3: play

 public static function play($params)
 {
     $username = !self::checkAuth($params);
     if ($username) {
         echo "<root>\n\t<error code='400'>Invalid login</error>\n</root>";
         return;
     }
     if ($song = OC_MEDIA_COLLECTION::getSong($params['song'])) {
         OC_Util::setupFS($song["song_user"]);
         header('Content-type: ' . OC_Filesystem::getMimeType($song['song_path']));
         header('Content-Length: ' . $song['song_size']);
         OC_Filesystem::readfile($song['song_path']);
     }
 }
开发者ID:Teino1978-Corp,项目名称:Teino1978-Corp-owncloud_.htaccess-,代码行数:14,代码来源:owncloud_apps_media_lib_ampache.php

示例4: play

 public function play($params)
 {
     if (!$this->checkAuth($params)) {
         $this->error(400, 'Invalid Login');
     }
     if ($song = $this->collection->getSong($params['song'])) {
         \OC_Util::setupFS($song["song_user"]);
         header('Content-type: ' . \OC_Filesystem::getMimeType($song['song_path']));
         \OC_Filesystem::readfile($song['song_path']);
     }
 }
开发者ID:CDN-Sparks,项目名称:owncloud,代码行数:11,代码来源:ampache.php

示例5: OC_Template

        $breadcrumbNav->assign("baseURL", OC_Helper::linkTo("files_sharing", "get.php") . "?token=" . $token . "&path=");
        $list = new OC_Template("files", "part.list", "");
        $list->assign("files", $files);
        $list->assign("baseURL", OC_Helper::linkTo("files_sharing", "get.php") . "?token=" . $token . "&path=");
        $list->assign("downloadURL", OC_Helper::linkTo("files_sharing", "get.php") . "?token=" . $token . "&path=");
        $list->assign("readonly", true);
        $tmpl = new OC_Template("files", "index", "user");
        $tmpl->assign("fileList", $list->fetchPage());
        $tmpl->assign("breadcrumb", $breadcrumbNav->fetchPage());
        $tmpl->assign("readonly", true);
        $tmpl->printPage();
    } else {
        //get time mimetype and set the headers
        $mimetype = OC_Filesystem::getMimeType($source);
        header("Content-Transfer-Encoding: binary");
        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Pragma: public");
        header('Content-Disposition: filename="' . basename($source) . '"');
        header("Content-Type: " . $mimetype);
        header("Content-Length: " . OC_Filesystem::filesize($source));
        //download the file
        @ob_clean();
        OC_Filesystem::readfile($source);
    }
} else {
    header("HTTP/1.0 404 Not Found");
    $tmpl = new OC_Template("", "404", "guest");
    $tmpl->printPage();
    die;
}
开发者ID:Teino1978-Corp,项目名称:Teino1978-Corp-owncloud_.htaccess-,代码行数:31,代码来源:owncloud_apps_files_sharing_get.php

示例6: get

 /**
  * return the content of a file or return a zip file containning multiply files
  *
  * @param dir  $dir
  * @param file $file ; seperated list of files to download
  */
 public static function get($dir, $files)
 {
     if (strpos($files, ';')) {
         $files = explode(';', $files);
     }
     if (is_array($files)) {
         $zip = new ZipArchive();
         $filename = sys_get_temp_dir() . "/ownCloud.zip";
         if ($zip->open($filename, ZIPARCHIVE::CREATE) !== TRUE) {
             exit("cannot open <{$filename}>\n");
         }
         foreach ($files as $file) {
             $file = $dir . '/' . $file;
             if (OC_Filesystem::is_file($file)) {
                 $tmpFile = OC_Filesystem::toTmpFile($file);
                 self::$tmpFiles[] = $tmpFile;
                 $zip->addFile($tmpFile, basename($file));
             } elseif (OC_Filesystem::is_dir($file)) {
                 self::zipAddDir($file, $zip);
             }
         }
         $zip->close();
     } elseif (OC_Filesystem::is_dir($dir . '/' . $files)) {
         $zip = new ZipArchive();
         $filename = sys_get_temp_dir() . "/ownCloud.zip";
         if ($zip->open($filename, ZIPARCHIVE::CREATE) !== TRUE) {
             exit("cannot open <{$filename}>\n");
         }
         $file = $dir . '/' . $files;
         self::zipAddDir($file, $zip);
         $zip->close();
     } else {
         $zip = false;
         $filename = $dir . '/' . $files;
     }
     if ($zip or OC_Filesystem::is_readable($filename)) {
         header('Content-Disposition: attachment; filename="' . basename($filename) . '"');
         header('Content-Transfer-Encoding: binary');
         header('Expires: 0');
         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
         header('Pragma: public');
         if ($zip) {
             header('Content-Type: application/zip');
             header('Content-Length: ' . filesize($filename));
         } else {
             header('Content-Type: ' . OC_Filesystem::getMimeType($filename));
             header('Content-Length: ' . OC_Filesystem::filesize($filename));
         }
     } elseif ($zip or !OC_Filesystem::file_exists($filename)) {
         header("HTTP/1.0 404 Not Found");
         $tmpl = new OC_Template('', '404', 'guest');
         $tmpl->assign('file', $filename);
         $tmpl->printPage();
         // 			die('404 Not Found');
     } else {
         header("HTTP/1.0 403 Forbidden");
         die('403 Forbidden');
     }
     @ob_end_clean();
     if ($zip) {
         readfile($filename);
         unlink($filename);
     } else {
         OC_Filesystem::readfile($filename);
     }
     foreach (self::$tmpFiles as $tmpFile) {
         if (file_exists($tmpFile) and is_file($tmpFile)) {
             unlink($tmpFile);
         }
     }
 }
开发者ID:Teino1978-Corp,项目名称:Teino1978-Corp-owncloud_.htaccess-,代码行数:77,代码来源:owncloud_lib_files.php

示例7: header

            $songId = OC_MEDIA_COLLECTION::getSongByPath($arguments['path']);
            OC_MEDIA_COLLECTION::registerPlay($songId);
            header('Content-Type:' . $ftype);
            // calc an offset of 24 hours
            $offset = 3600 * 24;
            // calc the string in GMT not localtime and add the offset
            $expire = "Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
            //output the HTTP header
            header($expire);
            header('Cache-Control: max-age=3600, must-revalidate');
            header('Pragma: public');
            header('Accept-Ranges: bytes');
            header('Content-Length: ' . OC_Filesystem::filesize($arguments['path']));
            $gmt_mtime = gmdate('D, d M Y H:i:s', OC_Filesystem::filemtime($arguments['path'])) . ' GMT';
            header("Last-Modified: " . $gmt_mtime);
            OC_Filesystem::readfile($arguments['path']);
            exit;
        case 'find_music':
            OC_JSON::encodedPrint(findMusic());
            exit;
    }
}
function findMusic($path = '')
{
    $music = array();
    $dh = OC_Filesystem::opendir($path);
    if ($dh) {
        while ($filename = readdir($dh)) {
            if ($filename[0] != '.') {
                $file = $path . '/' . $filename;
                if (OC_Filesystem::is_dir($file)) {
开发者ID:Teino1978-Corp,项目名称:Teino1978-Corp-owncloud_.htaccess-,代码行数:31,代码来源:owncloud_apps_media_ajax_api.php

示例8: header

if (OC_User::checkPassword($user, $pass)) {
    OC_Util::setupFS($user);
    OC_MEDIA_COLLECTION::$uid = $user;
} else {
    exit;
}
if (isset($_POST['play']) and $_POST['play'] == 'true') {
    if (!isset($_POST['song'])) {
        exit;
    }
    $song = OC_MEDIA_COLLECTION::getSong($_POST['song']);
    $ftype = OC_Filesystem::getMimeType($song['song_path']);
    header('Content-Type:' . $ftype);
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . OC_Filesystem::filesize($song['song_path']));
    OC_Filesystem::readfile($song['song_path']);
}
$artist = isset($_POST['artist']) ? '%' . $_POST['artist'] . '%' : '';
$album = isset($_POST['album']) ? '%' . $_POST['album'] . '%' : '';
$song = isset($_POST['song']) ? $_POST['song'] : '';
$artist = OC_MEDIA_COLLECTION::getArtistId($artist);
$album = OC_MEDIA_COLLECTION::getAlbumId($album, $artist);
$songs = OC_MEDIA_COLLECTION::getSongs($artist, $album, $song);
$baseUrl = OC_Util::getServerURL() . OC_Helper::linkTo('media', 'tomahawk.php');
$results = array();
foreach ($songs as $song) {
    $results[] = (object) array('artist' => OC_MEDIA_COLLECTION::getArtistName($song['song_artist']), 'album' => OC_MEDIA_COLLECTION::getAlbumName($song['song_album']), 'track' => $song['song_name'], 'source' => 'ownCloud', 'mimetype' => OC_Filesystem::getMimeType($song['song_path']), 'extension' => substr($song['song_path'], strrpos($song['song_path'], '.')), 'url' => $baseUrl . '?play=true&song=' . $song['song_id'], 'bitrate' => round($song['song_id'] / $song['song_length'], 0), 'duration' => round($song['song_length'], 0), 'size' => $song['song_size'], 'score' => (double) 1.0);
}
OC_JSON::encodedPrint($results);
开发者ID:Teino1978-Corp,项目名称:Teino1978-Corp-owncloud_.htaccess-,代码行数:31,代码来源:owncloud_apps_media_tomahawk.php


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