billgates2000 Posted May 25, 2006 Share Posted May 25, 2006 Hi, I have uploaded my mp3 collection on my webserver, but in a folder below the published directory so that it cannot be accessed from the web. However, I would like my friends to be able to download a small part of an mp3 file they request (say, 10%). I found the following script which does the job, i.e. it sends a file from the webserver to the browser:// Demo - send a (binary) file$file = "ireland.jpg";$fp = fopen($file,"r") ;header("Content-Type: image/jpeg");while (! feof($fp)) { $buff = fread($fp,4096); print $buff; }My question is, how can this script be modified so that:1. It calculates the total size of the file to be send, and2. Send only 10% of the filesize to the browser.I have done this in ASP it was really easy, but now I'm moving my site to PHP and I'm really not familliar with this. Thanks a lot. Quote Link to comment https://forums.phpfreaks.com/topic/10418-sending-a-file-to-browser/ Share on other sites More sharing options...
gerkintrigg Posted May 25, 2006 Share Posted May 25, 2006 I guess the simple answer would be to add an ASP tag in if you can, but perhaps it's not to most beautifully elegant method. Presuming you have streaming you'd probably need to use something like the $_FILES['requested_file']['size'] type command to find out it's size... not really sure how to only download some of it though...I'll be watching this post with interest. Quote Link to comment https://forums.phpfreaks.com/topic/10418-sending-a-file-to-browser/#findComment-38916 Share on other sites More sharing options...
trq Posted May 25, 2006 Share Posted May 25, 2006 Never done it, but maybe try something like...[code]$file = "ireland.jpg";$fp = fopen($file,"r");$snippet = ftruncate($fp,filesize($fp) / 10);header("Content-Type: image/jpeg");while (!feof($snippet)) { $buff = fread($snippet,4096); print $buff;}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/10418-sending-a-file-to-browser/#findComment-38922 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.