PHP files are streamed in a streaming way

Source: Internet
Author: User
Tags readfile what header
File stream Flow Mode transfer

Scene:
The client gets the MP3 file on the server to play, but for some reason the client cannot write the file, that is, the operation cannot be downloaded.
The idea now is to read the MP3 buffer into memory with fopen-fread->echo on the PHP side, and the client receives the buffer in memory and plays the sound in memory.

Problem:
Now there is a 5143-byte Mp3 on the server, but the client only receives 5042. Test is that some characters are escaped, in the Internet to find a lot of methods, seems to be not good, PHP learned, what method can let him do not escape to get the correct file buffer.


Reply to discussion (solution)

fopen using ' RB ' to open

fopen using ' RB ' to open
Well, it's been tried. I can't.

yge.me/xx.mp3/index.php

index.php
Header ("Location:http://yge.me/x.mp3");
The full URL address of the MP3.
X.mp3 for Real files
?>

1, with Echo file_get_contents (' filename '); No other issues to consider
2, with ReadFile (' filename '); No other issues to consider
3, the client can write files, not the service side can control things

1, with Echo file_get_contents (' filename '); No other issues to consider
2, with ReadFile (' filename '); No other issues to consider
3, the client can write files, not the service side can control things


In the afternoon, I was sure that echo file_get_contents (' filename ') should also be problematic.
I compared the hex data to find that the 0D was all lost, that is, newline
I have just received the data on the client (C + +) to start printing, OD is not, it should be sent over the time to escape it.
Why not let such a string escape?

What do you want with 0x0d?
Aren't you MP3? Isn't it normal not to have 0x0d?

What do you want with 0x0d?
Aren't you MP3? Isn't it normal not to have 0x0d?

Well, this character may not be a newline in mp3. Because it seems that without these characters mp3 is the noise. He is just a byte stream so it is normal to appear 0x0d, after all, in bytes 0-ff these 256 kinds.
Well, my idea is to assume that the file size is 5000 bytes, then transfer 5000 bytes, so it's definitely not noisy.

MP3 is a compression code, you want to let him not "noise", then a section of the spread of the whole

Yes, yes. But 0x0d will not transfer, by PHP as a space to remove my use Pack ("C1", "13") also shows that 0x0d cause my data is incomplete.

MP3 is a compression code, you want to let him not "noise", then a section of the pass-through Ah yes. But 0x0d will not transfer, by PHP as a space to remove my use Pack ("C1", "13") also shows that 0x0d cause my data is incomplete.

No kidding.
What is your basis?

No kidding.
What is your basis?



Look at the picture as the original text, the next part of the C + + memory debugging is not a few 0x0d. No fragments of this can be right.

PHP code on the following three words
Echo file_get_contents ("/var/www/soundeng/good.mp3");
?>

No kidding.
What is your basis?

Then the C + + part is to receive the original data certainly will not escape, so should be the PHP aspect escaped.
I tried the Echo pack ("C1", "13"); --Show received is also 00 guesses should be escaped, but is not familiar with PHP ...

I have a question, your PHP will not be sent to the header, right? What header?

The loss of 0x0d is certainly not the PHP side of the problem, otherwise the images emitted by PHP and a variety of binary data are not destroyed it? How come you're the only one
I feel like a problem with your C program, if you're using fgets to read the data.

I have a question, your PHP will not be sent to the header, right? What header? Tried the header of stream muti-byte.

The loss of 0x0d is certainly not the PHP side of the problem, otherwise the images emitted by PHP and a variety of binary data are not destroyed it? How come you're the only one
I feel like a problem with your C program, if you're using fgets to read the data.
Well, I also think it is not to add something in PHP file Ah? Represents this is a flow ... Well, I didn't use fget to read it. I sent an HTTP request in C and then called the system's API to read it, and maybe this time it was escaped. OK, thank you, I'll try again.

  • 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.