wiseguy Posted September 22, 2006 Share Posted September 22, 2006 I have a topsites script that is displaying an error after moving to a new web host. The error reads:[code]Warning: fread() [function.fread]: Length parameter must be greater than 0. in /home/karaoket/public_html/top-karaoke-sites/admin/lib/class.functions.php on line 723[/code]Any ideas on what would cause this? Quote Link to comment https://forums.phpfreaks.com/topic/21666-script-error/ Share on other sites More sharing options...
Daniel0 Posted September 22, 2006 Share Posted September 22, 2006 Could you show us the source code? We can't help you if we do not have it. Quote Link to comment https://forums.phpfreaks.com/topic/21666-script-error/#findComment-96733 Share on other sites More sharing options...
ronverdonk Posted September 22, 2006 Share Posted September 22, 2006 You either specified the wrong length in the second parameter of the fread or the file is empty.Ronald 8) Quote Link to comment https://forums.phpfreaks.com/topic/21666-script-error/#findComment-96740 Share on other sites More sharing options...
akitchin Posted September 22, 2006 Share Posted September 22, 2006 just as ronald said, wrong second parameter. my guess is that you're leaving it out:[quote]string fread ( resource handle, int length )[/quote]from the php manual - note that the second parameter is NOT optional. this is usually what an fread() should look like:$contents = fread($handle, [b]filesize('file name here')[/b]); Quote Link to comment https://forums.phpfreaks.com/topic/21666-script-error/#findComment-96746 Share on other sites More sharing options...
wiseguy Posted September 22, 2006 Author Share Posted September 22, 2006 The script was working before I moved it to a new host. I simply copied the script files and imported the database. The function at line 723 is: [code]function get_file($url,$read='r') { $a = fread(fopen($url, $read),filesize ($url)); return $a;[/code] Quote Link to comment https://forums.phpfreaks.com/topic/21666-script-error/#findComment-96758 Share on other sites More sharing options...
Daniel0 Posted September 22, 2006 Share Posted September 22, 2006 You could just change it to: [code]function get_file($url,$read='r') { $a = fread(fopen($url, $read)); return $a;[/code]The filesize thing just gets the total filesize, but fread will by default read everything, so you do not need that. Quote Link to comment https://forums.phpfreaks.com/topic/21666-script-error/#findComment-96760 Share on other sites More sharing options...
wiseguy Posted September 22, 2006 Author Share Posted September 22, 2006 [quote author=Daniel0 link=topic=109070.msg439439#msg439439 date=1158937117]You could just change it to: [code]function get_file($url,$read='r') { $a = fread(fopen($url, $read)); return $a;[/code]The filesize thing just gets the total filesize, but fread will by default read everything, so you do not need that.[/quote]That just produced another error[code]Warning: Wrong parameter count for fread() in /home/karaoket/public_html/top-karaoke-sites/admin/lib/class.functions.php on line 723[/code] Quote Link to comment https://forums.phpfreaks.com/topic/21666-script-error/#findComment-96771 Share on other sites More sharing options...
Daniel0 Posted September 22, 2006 Share Posted September 22, 2006 Hmm. Apparently fread [i]do[/i] require the length paramenter. Didn't though it did...Well, this should work: [code]function get_file($url) { return file_get_contents($url);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/21666-script-error/#findComment-96774 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.