how to download the video using php script

后端 未结 2 405
再見小時候
再見小時候 2021-01-13 22:59

In my program I want to add a download option to download the currently straming video. I tried this code:

$psp = \"Tom_20_amp__20Jerry_20race-1.flv\";
heade         


        
相关标签:
2条回答
  • 2021-01-13 23:41

    If you are looking to allow files to be downloaded instead of streamed then something like this should work. You will obviously need to change the paths.

    // We'll be outputting a PDF
    header('Content-type: application/pdf');
    
    // It will be called downloaded.pdf
    header('Content-Disposition: attachment; filename="download.pdf"');
    
    // The PDF source is in original.pdf
    readfile('original.pdf');
    

    EDIT

    In your case it will be something like this.

    // We'll be outputting a video
    header('Content-type: video/flv');
    
    // It will be called video.flv
    header('Content-Disposition: attachment; filename="video.flv"');
    
    // The PDF source is in original.flv
    readfile('original.flv');
    
    0 讨论(0)
  • 2021-01-13 23:49

    Change you're header from :

    header("Content-type:application/octet-stream");
    

    To :

    header("Content-type: video/flv");
    

    Then you can do :

    header("Content-Disposition:attachment;filename=\"$psp\"");
    //allways a good idea to let the browser know how much data to expect
    header("Content-length: " . filesize($psp) . "\n\n"); 
    echo file_get_contents($psp); //$psp should contain the full path to the video
    
    0 讨论(0)
提交回复
热议问题