uc7 Posted March 1, 2010 Share Posted March 1, 2010 Hi All, I'm pretty new at PHP so I hope this isn't too easy. I did spent the requisite two hours banging my head on a keyboard before posting it however. My wife has a site, and she has some mp3 songs on it people will download. I'm looking for a script that will download the mp3 file to the client PC. From the manual site I found this: <?php @ob_end_clean(); // Only allow mp3 files $allowedFileType = "mp3"; // Set the filename based on the URL's query string $theFile = $_REQUEST['theFile']; // Get info about the file $f = pathinfo($theFile); // Check the extension against allowed file types if(strtolower($f['extension']) != strtolower($allowedFileType)) exit; // Make sure the file exists if (!file_exists($theFile)) exit; // Set headers header("Pragma: public"); header("Expires: Thu, 19 Nov 1981 08:52:00 GMT"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: private"); header("Content-Transfer-Encoding: binary"); header("Content-Type: audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3"); // This line causes the browser's "save as" dialog header( 'Content-Disposition: attachment; filename="'.$f['basename'].'"' ); // Length required for Internet Explorer header("Content-Length: ".@urldecode(@filesize($theFile))); // Open file if (($f = fopen($theFile, 'rb')) === false) exit; // Push file while (!feof($f)) { echo fread($f, (1*(1024*1024))); flush(); @ob_flush(); } // Close file fclose($f); exit; ?> However copying it into the header of a html file, and opening with ~./fileget.php?file=nameOfSong.mp3, where the mp3 file is in the same folder as the php script gets me this error: Parse error: syntax error, unexpected T_ECHO in /home/sites/lolipop.jp/users/lolipop.jp-dp39285170/web/dev/gospel/dload/oto/fileget.php on line 43 Line 43 is "echo fread($f, (1*(1024*1024))); " Tried changing it from echo fread($f, (1*(1024*1024))); to echo fread($f, (8*(1024*1024))); and the error changed again. Parse error: syntax error, unexpected T_STRING in /home/sites/lolipop.jp/users/lolipop.jp-dp39285170/web/dev/gospel/dload/oto/fileget.php on line 44 Link to comment https://forums.phpfreaks.com/topic/193768-help-with-scripts-to-download-mp3-files-to-a-client/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 1, 2010 Share Posted March 1, 2010 The posted code does not produce a php parse error. There must be something present in your actual source file that the copy/paste into the forum post filtered out. I would recommend copy/pasting what you posted here into a completely new file and trying it. Link to comment https://forums.phpfreaks.com/topic/193768-help-with-scripts-to-download-mp3-files-to-a-client/#findComment-1019844 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.