marklarah Posted March 19, 2009 Author Share Posted March 19, 2009 Oh dude....I love you. Solved, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/150135-download-file-through-php/page/2/#findComment-788743 Share on other sites More sharing options...
MadTechie Posted March 19, 2009 Share Posted March 19, 2009 Your welcome Can you click the solved button (bottom left) please Quote Link to comment https://forums.phpfreaks.com/topic/150135-download-file-through-php/page/2/#findComment-788746 Share on other sites More sharing options...
marklarah Posted March 19, 2009 Author Share Posted March 19, 2009 Is there anyway to get the file download size? Quote Link to comment https://forums.phpfreaks.com/topic/150135-download-file-through-php/page/2/#findComment-788759 Share on other sites More sharing options...
marklarah Posted March 19, 2009 Author Share Posted March 19, 2009 Can I do that with curl? Quote Link to comment https://forums.phpfreaks.com/topic/150135-download-file-through-php/page/2/#findComment-788768 Share on other sites More sharing options...
MadTechie Posted March 19, 2009 Share Posted March 19, 2009 you could try $bytes = curl_getinfo($curl_handler, CURLINFO_CONTENT_LENGTH_DOWNLOAD); Quote Link to comment https://forums.phpfreaks.com/topic/150135-download-file-through-php/page/2/#findComment-788769 Share on other sites More sharing options...
marklarah Posted March 19, 2009 Author Share Posted March 19, 2009 you could try $bytes = curl_getinfo($curl_handler, CURLINFO_CONTENT_LENGTH_DOWNLOAD); How would I implement that into the existing script? Quote Link to comment https://forums.phpfreaks.com/topic/150135-download-file-through-php/page/2/#findComment-788776 Share on other sites More sharing options...
marklarah Posted March 19, 2009 Author Share Posted March 19, 2009 It does nothing. What do I do with $bytes? Quote Link to comment https://forums.phpfreaks.com/topic/150135-download-file-through-php/page/2/#findComment-788794 Share on other sites More sharing options...
marklarah Posted March 19, 2009 Author Share Posted March 19, 2009 I removed $bytes, did nothing What do I do ??? ??? ??? Quote Link to comment https://forums.phpfreaks.com/topic/150135-download-file-through-php/page/2/#findComment-788804 Share on other sites More sharing options...
MadTechie Posted March 19, 2009 Share Posted March 19, 2009 It does nothing. What do I do with $bytes? $bytes is the file size! as you requested.. Is there anyway to get the file download size? i don't know what you what to do with it! Quote Link to comment https://forums.phpfreaks.com/topic/150135-download-file-through-php/page/2/#findComment-788806 Share on other sites More sharing options...
marklarah Posted March 19, 2009 Author Share Posted March 19, 2009 Well the download says like "15mb of ? downloaded" How do I get it to say "15mb of 17mb downloaded" or whatever? Quote Link to comment https://forums.phpfreaks.com/topic/150135-download-file-through-php/page/2/#findComment-788890 Share on other sites More sharing options...
marklarah Posted March 19, 2009 Author Share Posted March 19, 2009 Well the download says like "15mb of ? downloaded" How do I get it to say "15mb of 17mb downloaded" or whatever? ? Quote Link to comment https://forums.phpfreaks.com/topic/150135-download-file-through-php/page/2/#findComment-788908 Share on other sites More sharing options...
marklarah Posted March 19, 2009 Author Share Posted March 19, 2009 wait, can this even be done? Quote Link to comment https://forums.phpfreaks.com/topic/150135-download-file-through-php/page/2/#findComment-788919 Share on other sites More sharing options...
corbin Posted March 19, 2009 Share Posted March 19, 2009 Depends how the file is downloaded. Quote Link to comment https://forums.phpfreaks.com/topic/150135-download-file-through-php/page/2/#findComment-788921 Share on other sites More sharing options...
marklarah Posted March 19, 2009 Author Share Posted March 19, 2009 well I have this header("Content-Type: application/octet-stream;"); header('Content-Disposition: attachment; filename="'.$name.'"'); $curl_handler = curl_init(); curl_setopt($curl_handler, CURLOPT_URL, $url); curl_setopt($curl_handler, CURLOPT_RETURNTRANSFER, 0); curl_setopt($curl_handler, CURLOPT_BINARYTRANSFER, 1); //$data = curl_getinfo($curl_handler, CURLINFO_CONTENT_LENGTH_DOWNLOAD); curl_exec($curl_handler); curl_close($curl_handler); exit; Quote Link to comment https://forums.phpfreaks.com/topic/150135-download-file-through-php/page/2/#findComment-788929 Share on other sites More sharing options...
corbin Posted March 19, 2009 Share Posted March 19, 2009 Not possible that way since cURL simply downloads the full file in one swoop (well, probably not 1 swoop, but it's wrapped in a function call, so you have no idea what's going on). You could use sockets and sort of achieve what you want. Quote Link to comment https://forums.phpfreaks.com/topic/150135-download-file-through-php/page/2/#findComment-788955 Share on other sites More sharing options...
marklarah Posted March 19, 2009 Author Share Posted March 19, 2009 How would I do that? Quote Link to comment https://forums.phpfreaks.com/topic/150135-download-file-through-php/page/2/#findComment-789011 Share on other sites More sharing options...
corbin Posted March 20, 2009 Share Posted March 20, 2009 This could use some better error handling, and if I sat here and thought about it, I could probably optimize it some, but: <?php define('BUFFER_SIZE', 8192); define('ALERT_SIZE', 1024); //alert each KB $sock = fsockopen('localhost', 80); $headers = "GET /somefile.php HTTP/1.1 Host: localhost Connection: close \r\n"; $hl = strlen($headers); if(fwrite($sock, $headers) == $hl) { //All content was written successfully. $content = $line = ''; //First get the headers using fgets. $length = -1; while(!feof($sock)) { $line = trim(fgets($sock)); if(empty($line)) break; if(stripos('Content-Length:', $line)) { //Woo, there's a content-length header. $length = preg_replace('~[^0-9]~', '', $line); } } //Done with headers.... Get content now. if($length != 0) { //Uhmm... if length is 0, that means that Content-Length: 0 was sent, in which case, there is not content. $size_so_far = 0; //number of bytes downloaded. $len = ($length > 0) ? $length : 'N/A'; $factor = 0; //No better name for this x.x. while(!feof($sock)) { $tmp = stream_get_contents($sock, BUFFER_SIZE); $content .= $tmp; $size_so_far += strlen($tmp); if($length != -1 && $size_so_far == $length) break; if(floor($size_so_far/ALERT_SIZE) > $factor) { $factor = floor($size_so_far/ALERT_SIZE); $bytes = $factor*ALERT_SIZE; //yeah, this could be wrong, but it will look prettier ;p. echo "{$bytes} bytes downloaded of {$len} bytes.\n"; } } echo "Done downloading {$size_so_far} bytes.\n"; } } Quote Link to comment https://forums.phpfreaks.com/topic/150135-download-file-through-php/page/2/#findComment-789023 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.