Php cannot play the flv or mp4 files downloaded

Source: Internet
Author: User
Tags flv file
Php cannot download flv files or mp4 files. if you want to transmit the flv playback address or mp4 playback address through POST, you can directly download the files. it is easy to download and directly receive POST data. the format of POST data is similar: a. com1.flv, then downloaded through PHP, tested two methods (only... Php cannot play the flv or mp4 files downloaded

If you want to transmit the flv playback address or mp4 playback address through POST and then download it directly, it is very easy to download and directly receive POST data. the format of POST data is similar: http://a.com/1.flv. after PHP is downloaded, the two methods are tested (only simplified code for download is posted ):

 

Or:

 

The 1. flv file is successfully downloaded, but cannot be played after the download. you can download the 1. flv file using linux wget http://a.com/1.flv. An error occurs when you directly download the file in PHP:


Comparing the file size, it is found that the file cannot be played three more bytes:

Then the vim editor finds that the file starts with three more bytes, but you do not know how many of them are. you can delete these three bytes to play back the file:

No answers can be found on the Internet .. I really don't know where the problem is. could you help me? =

Solution:

These three characters are the legendary BOM.

You are used to download the php file, the format is UTF-8 with BOM, with Notepad ++ look at it,

Or pull out all your php files and remove them?

/*** Remove the BOM of a string ** @ param string $ str input string * @ return string output string */function removeBOM ($ str) {$ str_2 = substr ($ str, 0, 2); $ str_3 = substr ($ str, 0, 3); // $ str_2. $ str {2}; $ str_4 = substr ($ str, 0, 4); // $ str_3. $ str {3}; if ($ str_3 = pack ('CCC ', 0xef, 0xbb, 0xbf) // UTF-8 return substr ($ str, 3 ); elseif ($ str_2 = pack ('CC', 0xfe, 0xff) | $ str_2 = pack ('CC', 0xff, 0xfe )) // unicode return substr ($ str, 2); elseif ($ str_4 = pack ('cccc', 0x00,0x00, 0xfe, 0xff) | $ str_4 = pack ('cccc', 0xff, 0xfe, 0 x) // UTF-32 return substr ($ str, 4); return $ str ;}

Related articles:

PHP converts a video to MP4 and obtains a video preview image.

Php uses memcoder to convert a video to mp4 format

PHP + FFMPEG enables automatic transcoding of videos into H264 standard Mp4 files

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.