marklarah Posted May 7, 2009 Share Posted May 7, 2009 Silly PHP.... Actually I'm more it's just silly me, probably something stupid I'm missing here, but what exactly could be wrong with this simple download script? <?php function http_get($url) { $url_stuff = parse_url($url); $port = isset($url_stuff['port']) ? $url_stuff['port'] : 80; $fp = fsockopen($url_stuff['host'], $port); $query = 'GET ' . $url_stuff['path'] . " HTTP/1.0\n"; $query .= 'Host: ' . $url_stuff['host']; $query .= "\n\n"; fwrite($fp, $query); while ($tmp = fread($fp, 1024)) { $buffer .= $tmp; } preg_match('/Content-Length: ([0-9]+)/', $buffer, $parts); return substr($buffer, - $parts[1]); } header("Content-Description: File Transfer"); header("Content-Type: application/x-rar-compressed"); header("Content-Transfer-Encoding: binary"); header("Content-Disposition: attachment; filename=test.rar"); http_get('file url goes here'); ?> I guess that should work, but I get Fatal error: Cannot redeclare http_get() on the line referring to the } that closes the function. I can't see anything wrong with it...maybe you could point it out to me? Cheers... Quote Link to comment https://forums.phpfreaks.com/topic/157284-but-im-not-redeclaring-a-function/ Share on other sites More sharing options...
premiso Posted May 7, 2009 Share Posted May 7, 2009 http_get You sure are re declaring it. I am sure google would have enlightened you to that function. Quote Link to comment https://forums.phpfreaks.com/topic/157284-but-im-not-redeclaring-a-function/#findComment-828965 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 http_get You sure are re declaring it. I am sure google would have enlightened you to that function. Wow premiso's on a roll. He's really knocking these help topics down! Quote Link to comment https://forums.phpfreaks.com/topic/157284-but-im-not-redeclaring-a-function/#findComment-828968 Share on other sites More sharing options...
marklarah Posted May 7, 2009 Author Share Posted May 7, 2009 http_get You sure are re declaring it. I am sure google would have enlightened you to that function. I thought I was calling it. Quote Link to comment https://forums.phpfreaks.com/topic/157284-but-im-not-redeclaring-a-function/#findComment-828969 Share on other sites More sharing options...
marklarah Posted May 7, 2009 Author Share Posted May 7, 2009 Wait....so how do I call this function then with the download? Quote Link to comment https://forums.phpfreaks.com/topic/157284-but-im-not-redeclaring-a-function/#findComment-828970 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 You can't define http_get because it's already a built-in function. Change the function name. See this: function http_get($url) Quote Link to comment https://forums.phpfreaks.com/topic/157284-but-im-not-redeclaring-a-function/#findComment-828971 Share on other sites More sharing options...
marklarah Posted May 7, 2009 Author Share Posted May 7, 2009 Yeah I just tried that lol Thing i, I found this function on php.net so...I assumed it would be all working and such. EDIT: Right now, the page is just loading, surely it should initiate the download Quote Link to comment https://forums.phpfreaks.com/topic/157284-but-im-not-redeclaring-a-function/#findComment-828974 Share on other sites More sharing options...
premiso Posted May 7, 2009 Share Posted May 7, 2009 Thing i, I found this function on php.net so...I assumed it would be all working and such. So you found that function in the user comments somewhere? Well that function you found the creator most likely did not have probably works the same as http_get if you do not have PECL installed. So it worked for him. EDIT: I do not think it works the same. Either way to use it, change your function name to something like : function my_http_get and your script should work just fine, given that function does what you want. If not maybe the http_get function does what you want and you do not have to use a user-defined function. Quote Link to comment https://forums.phpfreaks.com/topic/157284-but-im-not-redeclaring-a-function/#findComment-828976 Share on other sites More sharing options...
marklarah Posted May 7, 2009 Author Share Posted May 7, 2009 Thing i, I found this function on php.net so...I assumed it would be all working and such. So you found that function in the user comments somewhere? Well that function you found the creator most likely did not have probably works the same as http_get if you do not have PECL installed. So it worked for him. EDIT: I do not think it works the same. Either way to use it, change your function name to something like : function my_http_get and your script should work just fine. http://php.oregonstate.edu/manual/en/features.remote-files.php Ctrl+f: 29-Apr-2008 01:18 05-Aug-2003 12:25 to find the post So I just renamed the function, and it finished loading the page, in a time that might of seemed it could have downloaded the file, but the file in my downloads folder is just Zero kilobytes Quote Link to comment https://forums.phpfreaks.com/topic/157284-but-im-not-redeclaring-a-function/#findComment-828980 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.