dstobkpm908182 2018-11-25 04:15
浏览 54

PHP - 我有下载高文件的问题

i Got the problem, my problem with high files. for example i have a 20mb file, its run without problem. them i give it 50mb file. its not load.....

this is my code:

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

after this i send data fo output function. the output code:

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

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

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

its work for all formats but when i use url like this:

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

its not work....

then use this urls :

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

it will work without any problem

i test any wayse but it not work...

there is problem with video files...

please help me....

Its Downloader Plugin (Check Access Users To Download Files) On Wordpress


after this i update my code to:

$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 );
}

after some tests i got underestand my problem with high files then i used this code for download:

$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;
}
}

its works... but when i played video by this way or downloading, my website goes down... is the other ways?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题