如何在 php 中读取放置在服务器上的视频文件 - 视频文件的名称包括 http 包装器
我正在使用以下代码,但 fseek
似乎出现警告,并返回 -1 而不是 0。
$file = fopen("http://www.example.com/public_html/data/video/temp.mov", "r") or exit("unable to open file");
fseek($file, -128, SEEK_END);
文件肯定会打开,但 fseek
不起作用。还有其他方法从服务器读取视频吗?
以下是错误信息
Warning: filesize() [function.filesize]: stat failed for
Warning: fseek() [function.fseek]: stream does not support seeking in
I am using the following code but there appears to be warning with fseek
and returns -1 instead of 0.
$file = fopen("http://www.example.com/public_html/data/video/temp.mov", "r") or exit("unable to open file");
fseek($file, -128, SEEK_END);
The file gets opened definately but fseek
doesn't work. Is there some other method to read video from server?
Following is the error message
Warning: filesize() [function.filesize]: stat failed for
Warning: fseek() [function.fseek]: stream does not support seeking in
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这一定是一些平台相关的问题。试试这个代码:
HTTP 包装器不支持查找。如果您想通过 HTTP 查找远程文件,您需要获取文件的大小。一种可能的方法是解释目录列表,或发出
HEAD
请求。当您知道文件大小时,可以使用 curl 和 范围如下。这也是获取远程文件大小的方法。
如何使用 cURL 下载文件(此示例将数据加载到 PHP 变量中,仅在您想处理数据时使用,如果您只想将其保存到外部文件中,请使用 CURLOPT_FILE 而不是 CURLOPT_RETURNTRANSFER):
It must be some platform dependant problem. Try this code:
HTTP wrapper does not support seeking. If you want to seek in a remote file thru HTTP you need to get the size of the file. One possible way is to interpret a directory listing, or make a
HEAD
request. When you know the filesize you can use curl and Range like here.This is also a method to get remote file size.
How to download a file with cURL (This example loads the data into a PHP variable, use only if you want to process the data, If you just want to save it into an external file use CURLOPT_FILE instead of CURLOPT_RETURNTRANSFER):