首页 > 解决方案 > PHP - 我在下载高文件时遇到问题

问题描述

我遇到了问题,我的高文件问题。例如我有一个 20mb 的文件,它的运行没有问题。他们我给它 50mb 的文件。它没有加载......

这是我的代码:

$file = './' . $elements[ $oindex ] . DIRECTORY_SEPARATOR . $elements[ $otype ] . DIRECTORY_SEPARATOR . $elements[ $odate ] . DIRECTORY_SEPARATOR . urldecode( $elements[ $ofile ] );

在此之后我发送数据输出功能。输出代码:

$file = fopen( $filename, 'r' );

$mimetype = mime_content_type( $file );
header( 'Content-Type: ' . $mimetype );

echo fpassthru( $file );
fclose( $file );

它适用于所有格式,但是当我使用这样的 url 时:

http://localhost/onwebsite_ir/c/files/ow_free/2018-11/y2mate.com%20-%20retrain_your_mind_new_motivational_video_very_powerful_xp2qjshr-r4_1080p.mp4

它不工作....

然后使用这个网址:

http://localhost/onwebsite_ir/c/files/ow_free/2018-11/NO%20EXCUSES%20-%20Best%20Motivational%20Video.mp4

http://localhost/onwebsite_ir/c/files/ow_portable_ocourses_on/2018-11/01%20-%20Introduction%20to%20the%20Tools%20used%20in%20Mobile%20Repairing%20(English).jpg

它可以正常工作

我测试了任何方法,但它不起作用......

视频文件有问题...

请帮我....

它在 Wordpress 上的下载器插件(检查访问用户以下载文件)


在此之后,我将代码更新为:

$file_size = filesize( $filename );
$file      = @fopen( $filename, "rb" );
if ( $file ) {
header( "Content-Disposition: attachment; filename=\"$fn\"" );
header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
header( "Content-Length: $file_size" );
$mimetype = mime_content_type( $file );
header( 'Content-Type: ' . $mimetype );
set_time_limit( 0 );
if ( $t == 'ow_free' ) {
echo fpassthru( $file );

}
fclose( $file );
}

经过一些测试后,我了解了我的高文件问题,然后我使用此代码进行下载:

$file_size = filesize( $filename );
$file      = @fopen( $filename, "rb" );
if ( $file ) {
header( "Content-Disposition: attachment; filename=\"$fn\"" );
header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
header( "Content-Length: $file_size" );
$mimetype = mime_content_type( $file );
header( 'Content-Type: ' . $mimetype );
set_time_limit( 0 );
fseek( $file, 0 );
while ( ! feof( $file ) ) {
print( @fread( $file, 1024 * 8 ) );
ob_flush();
flush();
if ( connection_status() != 0 ) {
@fclose( $file );
exit;
}
}

它的作品......但是当我通过这种方式播放视频或下载时,我的网站出现故障......是其他方式吗?

标签: phpfopenurldecode

解决方案


推荐阅读