Welcome to WebmasterWorld Guest from 54.162.155.183

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Need help with an empty file fread

Need help with an empty file fread

     
12:28 pm on Apr 13, 2006 (gmt 0)

10+ Year Member



Hi,

My partner coder, whose account I'm writing from, went to vacation for almost two weeks and left me helpless with an error that appeard after our host switched to newer php version.

Warning: Wrong parameter count for fread() in /home/www/somename/setup1.php on line 1390

I spent two days reading different forums and manuals trying to figure this out. aparantly the problem in newer version is that the file can not be 0 bytes. I tried to add couple of symbols to the file, but could not edit it since only the server have permissions to alter it. It has -rw-r-r mode with server ownership.

He is the code I belive which creates this statistic file:

$postfile = "feeds/post_HTML".$codeFile.".txt";
if (!file_exists($postfile)) {
session_unset();
header("Location: [somesite.com...]

}

$fp = fopen($postfile, "r");
$file_contents = fread($fp, filesize($postfile));
fclose($fp);

$statisticsFile = "feeds/count_feeds.sta";
$feeds_count = 0;
if (file_exists($statisticsFile)) {
$fp = fopen($statisticsFile, "r");
$feeds_count = fread($fp, filesize($statisticsFile));
fclose($fp);
}
$orders_count++;

if ($fp = fopen("$statisticsFile", 'w')) {
fwrite ($fp, $feeds_count);
}
fclose($fp);

$to_send.=$file_contents;

Please could someone let me know what is a possible solution.

Thanks

3:04 pm on Apr 13, 2006 (gmt 0)

5+ Year Member



Is it pulling any of the variables from a POST or GET form submission? I ask because:
In PHP 4.2.0 and later, the default value for the PHP directive register_globals is off. This is a major change in PHP. Having register_globals off affects the set of predefined variables available in the global scope. For example, to get DOCUMENT_ROOT you'll use $_SERVER['DOCUMENT_ROOT'] instead of $DOCUMENT_ROOT, or $_GET['id'] from the URL http://www.example.com/test.php?id=3 instead of $id, or $_ENV['HOME'] instead of $HOME.

If it is pulling something out of a form, and a php upgrade occured, thats probably the problem, I cant tell since im only seeing some of the code though.
3:44 pm on Apr 13, 2006 (gmt 0)

10+ Year Member



As far as I know this function send info about session to a secure server and then back to our server after an order was processed.

After the code I posted follows a payment form with this element in it:

<form name=\"info\" onsubmit=\"return msab();\" action=\"https://id111.somesecureserver.net/somesite/base.php\" method=\"post\">

<input type=\"hidden\" name=\"shop_action\" value=\"process_order\">

So I beleive it does pull froma form. The codeFile is being declared earlier:

function submit_order() {

global $cart;
global $codeFile;

Later in the code after the order form I found for functions:


$postfile = "feeds/post_Plane".$codeFile.".txt";
$fp = fopen($postfile, "r");
$plane = fread($fp, filesize($postfile));
//$to_send.=$plane;
fclose($fp);

$postfile = "feeds/post_Price".$codeFile.".txt";
$fp = fopen($postfile, "r");
$totalPrice1 = fread($fp, filesize($postfile));
fclose($fp);

But the error apears before the the form is processed right after a customer is sent to a secure server.

I'm sorry if I sound newbish, but scripting is my poor side.

4:19 pm on Apr 13, 2006 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



what exactly is on "line 1390" is that one of the fread functions you mentioned?
6:17 pm on Apr 13, 2006 (gmt 0)

10+ Year Member



Exactly is this:

$feeds_count = fread($fp, filesize($statisticsFile));

Thanks

I tried to add a little weight to the file with this:

$feeds_count = fread($fp, filesize($statisticsFile, 8092));

But it gave me another error next to the first one:


Warning: Wrong parameter count for filesize() in /home/www/veneerz/setup1.php on line 1390

[edited by: Artstart at 6:24 pm (utc) on April 13, 2006]

6:22 pm on Apr 13, 2006 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



any block with fread could be replaced as such

//$fp = fopen($postfile, "r");
//$file_contents = fread($fp, filesize($postfile));
$file_contents = file_get_contents($postfile);
//fclose($fp);

no open or close needed, just the single line using file_get_contents [php.net]

as noted on the page for fread [php.net]

Note: If you just want to get the contents of a file into a string, use file_get_contents() as it has much better performance than the code above.
6:30 pm on Apr 13, 2006 (gmt 0)

10+ Year Member



Worked like a charm :happy:

Thank you very much jatar_k

6:33 pm on Apr 13, 2006 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



my pleasure

you could do the same for any other fread that goes awry

 

Featured Threads

Hot Threads This Week

Hot Threads This Month