homepage Welcome to WebmasterWorld Guest from 54.227.67.175
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Need help with an empty file fread
Need help with an empty file fread
Artstart




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

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

 

thndr




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

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.

Artstart




msg:1265206
 3:44 pm on Apr 13, 2006 (gmt 0)

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.

jatar_k




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

what exactly is on "line 1390" is that one of the fread functions you mentioned?

Artstart




msg:1265208
 6:17 pm on Apr 13, 2006 (gmt 0)

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]

jatar_k




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

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.

Artstart




msg:1265210
 6:30 pm on Apr 13, 2006 (gmt 0)

Worked like a charm :happy:

Thank you very much jatar_k

jatar_k




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

my pleasure

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved