Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Question about Flac and php based carts (Read 6840 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Question about Flac and php based carts

Using Flac for commercial use at my site I'm offering 24/96 files of my classical releases for sale, I apologize if I explain the problem like a novice about Flac because I am a novice about using Flac so excuse me.
I'm using Flac for compression because almost all of my clients prefer it, first off my wav files average between 150 to 600mb not compressed I'm using a dedicated server to store them and I'm using a php based cart software my programmer is having a hard time trying to figure out why when you buy through the cart software and download the file and try to play the file on some players such as media monkey it works but on others like VLC it doesn't also when you try to decode the file off the Flac frontend you get a out of sync error message now on the other hand when you use a ftp client to download the file everything works fine, well I'm wondering if anybody has any experience with this situation because it is very frustrating.
  Can the php cart be adding any tags to the file ???
FYI the files that go through the software cart come down off the server at the same size as the file when it is on the server so it is not being cut off as it is being downloaded.
Hope I explained it so you guys understand any help would be greatly appreciated
Thanks

Question about Flac and php based carts

Reply #1
if you can save the flac file after each of the those different mechanisms and compare them, that will tell you if anything is getting modified.  if it's the same as the original, you can try the command line flac program in test mode (flac -t) to test it or use one of the other flac testers:

http://www.vuplayer.com/other.php
http://www.neilpopham.pwp.blueyonder.co.uk/flac-test.bat

it's also possible that some other program has added an id3 tag on the FLAC file which is a no-no.

Josh

Question about Flac and php based carts

Reply #2
I'm confused by the fact that both the source and downloaded file are the same size.  Are you talking bytes or just duration?  I suspect that the software is adding a header to the file due to the wrong content type being used.

One suggestion to help us diagnose:  create a small FLAC file, download it via the cart software, and then upload both files for us to download.

Josh could find the change in a jiffy, but any one of us may be able to help.

Have you tried comparing them in a hex editor?  Have you tried using multiple browsers?
I'm on a horse.

Question about Flac and php based carts

Reply #3
I'm confused by the fact that both the source and downloaded file are the same size.  Are you talking bytes or just duration?  I suspect that the software is adding a header to the file due to the wrong content type being used.

That was my guess or white space being appended (output buffer issues in PHP, see ob_start etc).

HDTT, The file comparison is essential in trouble shooting this.
daefeatures.co.uk

Question about Flac and php based carts

Reply #4
Thanks for all the help
I've put up 2 identical flac files on my server one is called original.flac and the other fromphpcart.flac the latter is the file off of the shopping cart which I'm having problems and the other is the original file for comparison
again if anybody could tell me what's up with them it would be greatly appreciated here is the address:
http://01688cb.netsolhost.com/public/

Question about Flac and php based carts

Reply #5
Oh come on, they're 90MB. Something smaller that I can use md5 on and download before I die of old age?
err... i'm not using windows any more ;)

Question about Flac and php based carts

Reply #6
The "fromphpcart.flac" has 0D0A 0D0A at the beginning and a 0D0A at the end. Your PHP script is almost certainly the culprit.

edit: ps they're not the same size.
daefeatures.co.uk

Question about Flac and php based carts

Reply #7
I had the benefit of putting my daughter to bed while I waited. 

There are four extra bytes at the beginning: 13, 10, 13, 10 (CRLF, CRLF)

There are two extra bytes at the end: 13, 10 (CRLF)

The page that is pushing the download must be writing these CRLF combos as well.

Edit: ... the benefit of the time to download, but not the good sense to check the thread before responding.
I'm on a horse.

Question about Flac and php based carts

Reply #8
How exactly is the PHP reading the file and sending it? Can we see some PHP code?

Question about Flac and php based carts

Reply #9
It almost sounds like the file is being sent as some kind of malformed HTTP response.  The headers are empty, and the FLAC is the body.

Question about Flac and php based carts

Reply #10
I agree with sbooth.

The HTTP standard says that (IIRC) an HTTP transfer is composed of the http version<crlf>HTTP headers<crlf><crlf>body.

I think PHP generates the necessary headers, but in this regard instead of using 2 <crlf>'s uses 3 <crlf>'s. Then, it appends 1 <crlf> at the end of the body. With HTML files, it's no problem (they'rs <crlf>-agnostic). With binaries, chaos.

Question about Flac and php based carts

Reply #11
I know sometimes with PHP if have a gap between the start of the file and the <?php or after the ?> can casue extra characters to go along for the ride.

Question about Flac and php based carts

Reply #12
Is there a way to elliminate the gaps before uploading??

Question about Flac and php based carts

Reply #13
Something like this should work:

Code: [Select]
<?php
header('Content-type: application/octet-stream');
readfile('music.flac');
?>


or whatever the right content type for .flacs is. No guarantee though...

edit: "Content-type: audio/x-flac" seems to be the right one.

Question about Flac and php based carts

Reply #14
Is there a way to elliminate the gaps before uploading??
The "gaps" are not in the FLAC file, but caused by the PHP script which pushes the download.

You need to look to the PHP code - the FLAC files are fine.
I'm on a horse.

Question about Flac and php based carts

Reply #15
I'm the programmer working on this issue.  Here's the source PHP:
(This is the source file currently used.)

header ("Pragma: private");
header ("Expires: " . $now);
header ("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header ("Cache-Control: private, must-revalidate");
header ("Content-Description: File Transfer");
header ("Content-Type: audio/x-flac");
header ("Accept-Ranges: bytes");
header ("Content-Disposition: attachment; filename=" . $this->fileName);
header ("Content-Transfer-Encoding: binary");
header ("Content-Length: " . filesize ($this->fullFilePath));

$handle = fopen ($this->fullFilePath, 'rb');
while (!feof ($handle)) {
    print (fread ($handle, 1024*8));
    flush ();
    ob_flush ();
}
fclose ($handle);


As to the note below, I really don't know why, I'm just trying to fix what was previously written.

Question about Flac and php based carts

Reply #16
Um, I'm a bit unclear. Is this the solution to the problem above?

Slightly OT: Why use $now for expiration? As the FLAC file most likely will not change in the near future, why not use a future date?

Question about Flac and php based carts

Reply #17
Um, I'm a bit unclear. Is this the solution to the problem above?
In part.  I tested the above code at work on a small file and it worked fine.

However, that code appears to be from a method of a class, which will be called by a PHP page.

Edit: Sorry, misread your post.  I'm assuming this is the code that was, and still is, in place.
I'm on a horse.