从php stdin保存大文件 [英] Save large files from php stdin
问题描述
请告诉我从php stdin保存大文件的最佳方法. iOS开发人员将大量视频内容发送给服务器,我必须将其存储到文件中.
Advise me the most optimal way to save large files from php stdin, please. iOS developer sends me large video content to server and i have to store it in to files.
我读取了包含视频数据的stdin线程,并将其写入文件.例如,通过这种方式:
I read the stdin thread with video data and write it to the file. For example, in this way:
$handle = fopen("php://input", "rb");
while (!feof($handle)) {
$http_raw_post_data .= fread($handle, 8192);
}
最好使用什么功能? file_get_contents还是fread或其他内容?
What function is better to use? file_get_contents or fread or something else?
推荐答案
不要使用file_get_contents
,因为它将尝试将文件的所有内容加载到字符串中
Don't use file_get_contents
because it would attempt to load all the content of the file into a string
file_get_contents()是阅读将文件内容转换为字符串.如果操作系统支持,它将使用内存映射技术来提高性能.
file_get_contents() is the preferred way to read the contents of a file into a string. It will use memory mapping techniques if supported by your OS to enhance performance.
确定您只想在服务器上创建电影文件..这是一种更有效的方法
Am sure you just want to create the movie file on your server .. this is a more efficient way
$in = fopen("php://input", "rb");
$out = fopen('largefile.dat', 'w');
while ( ! feof($in) ) {
fwrite($out, fread($in, 8192));
}
这篇关于从php stdin保存大文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!