song_of_solomon Posted April 15, 2008 Share Posted April 15, 2008 First of all, I don't care if the solution to this problem is a script written in PHP, perl, asp or javascript, or if someone shows how to do this via an html page... I just want to get this function working and have seen a lot of old forums on the same topic but not found a solution. HERE'S THE TASK: We have large mp3 files (30-60MBs in size) which we have recorded (no chance of copyright issues; it isn't somoene's music). The files need to remain at their current size and available on our website. I wish to make or use a script which will run when a user clicks on a download icon. The script would need to send the necessary headers which would cause the client browser to open the Save as dialog box. HERE'S THE PROBLEM: I already my webhost has configured the server to kills PHP script after 60 seconds and has PHP running in safe_mode. My script actually works but just doesn't complete because of the execution time limit. I have tried numerous variations but I'm not a huge programmer and don't know if the answer is staring me in the face or not. THE SIMPLIEST COPY ONE OF MY SCRIPTS WHICH STARTED THE DOWNLOAD BUT GETS KILLED: <?php $filename = $_GET['filename']; $strFileSize = filesize($filename); $strFileName = basename($filename); header("Pragma: public"); // required header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); // required for certain browsers header("Content-type: application/octet-stream"); header("Content-Transfer-Encoding: binary"); header("Content-Length: $strFileSize"); header('Content-Disposition: attachment; filename="' . $strFileName . '"'); readfile($filename); ?> THINGS I HAVE ALSO FOUND OUT: If I try reading the contents of the file into a variable I receive an out of memory error no matter which language the script is written in. Any help would be GREATLY appreciated!!! Link to comment https://forums.phpfreaks.com/topic/101248-php-script-times-out-while-performing-file-download-need-workaround/ Share on other sites More sharing options...
mbeals Posted April 15, 2008 Share Posted April 15, 2008 so you just want to click on the image to download the file? Why wouldn't a simple href tag work? Like <A href="/path/to/file.mp3"><img src ="/path/to/image/file.jpg></a> Link to comment https://forums.phpfreaks.com/topic/101248-php-script-times-out-while-performing-file-download-need-workaround/#findComment-517893 Share on other sites More sharing options...
micah1701 Posted April 15, 2008 Share Posted April 15, 2008 if you play the mp3 as an m3u file the user can stream it and you shouldn't need to worry about your script timing out. <?php $mp3Location = "/apache/var/www/path/to/filename.mp3"; header("Content-type: audio/m3u"); header("Content-Disposition: inline; filename=streamingauido.m3u"); ?> http://www.your_domain.com/<?php echo $mp3Location; ?> Link to comment https://forums.phpfreaks.com/topic/101248-php-script-times-out-while-performing-file-download-need-workaround/#findComment-517897 Share on other sites More sharing options...
song_of_solomon Posted April 15, 2008 Author Share Posted April 15, 2008 MORE INFORMATION: Sorry, I had hoped to be very thorough in posting my question but I left out some things which will help further define the need for this solution. OUR WEB SITE ALREADY HAS: 1) An icon a user can click to play the recorded mp3 directly through our web page without needing any software on the end-user's PC 2) An icon which will stream the mp3 to the end-user's PC and allow it to be played via whichever application is defined for playing files with the .mp3 extension. REASON FOR THE DOWNLOAD ICON: A lot of our end-users are older and lack computer knowledge or just want the ease to be able to click the download icon and save the mp3 file to their computer. They DO NOT want to have to know to just right-click on a link and choose Save Target As. I already have a note with those instructions above the mp3 files and still there are issues. I also have a pop-up bubble with the instruction on the existing download icon and they still don't always understand. IN SHORT: I'm am specifically looking for a solution which allows me to have an icon which when clicked opens the Save as dialog box and allows the complete transfer of large mp3 files (30-60MBs in size) to the end-user so they can store them on their PC or mp3 players. Thanks for your responses thus far, but yes, I need to download (not play it) the mp3 file from our website to end-user's PC. Link to comment https://forums.phpfreaks.com/topic/101248-php-script-times-out-while-performing-file-download-need-workaround/#findComment-517935 Share on other sites More sharing options...
micah1701 Posted April 16, 2008 Share Posted April 16, 2008 ah, i see. this doesn't answer your question - but I've had a similar problem and used a little javascript alert to tell people what to do. clicking the link to the mp3 just pops up the message telling them to right-click and save the file. see http://www.fbcmct.org/?p=9002 and click "save mp3" on one of the files to see it in action. Link to comment https://forums.phpfreaks.com/topic/101248-php-script-times-out-while-performing-file-download-need-workaround/#findComment-518500 Share on other sites More sharing options...
song_of_solomon Posted April 16, 2008 Author Share Posted April 16, 2008 Thanks Micah, I will try to use that approach in until something better comes along (if ever that happens!!!). Would it be possible for me to get a copy of the javascript you used in order to make the message window and the image(s) necessary to create the button? HOPEFULLY, I will hear from someone who has knowledge on how to either perform the process I illustrated above without it being subjected to a 60 second time limit, or how to submit the process as a subprocess (if that would get it away from being limited to a 60 second time limit. THIS IS A WILD STAB: Supposedly, they have packages out there where people can sell products on their website. I have seen where you can download software or media files using an e-commerce system once you paid for it. IN FACT, someone (and I can't remember who) was using software like that to make it possible to download software from their site and had notices along their site that the software or media file was free but you had to add it to your shopping cart in order to allow the software to handle the download process! If only I could remember where I saw that or find one of these packages which will handle the download and not die during the download. Your MP3s seem to be much smaller than the ones I am trying to transfer. My script might work in your case unless the person's bandwidth and connection spreed is too slow to complete the transfer before the 60 second limit. Thanks again... Link to comment https://forums.phpfreaks.com/topic/101248-php-script-times-out-while-performing-file-download-need-workaround/#findComment-518670 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.