I am using the following php class to convert text to speech: http://www.masnun.me/2009/12/14/googles-text-to-speech-api-a-php-wrapper-class.html
its using google’s API, and right now the code saves the file locally however I want it to stream the file to user’s browser by force. this is what I came up with:
function saveToFile($filename) {
$filename = trim($filename);
if(!empty($filename)) {
header("Content-type: application/octet-stream");
header('Content-length: ' . filesize($this->mp3data));
header('Content-Disposition: filename="' . $filename);
header('X-Pad: avoid browser bug');
header('Cache-Control: no-cache');
readfile($this->mp3data);
} else { return false; }
}
but the produced file is 0kb empty mp3 file. what am I doing wrong?
Does
readfileactually echo to the browser? If it’s just returning something it won’t work how you expect:I also understand that readfile works with a path, if that is the case, just try: