Jump to content

[SOLVED] Unable to open file to append


perdue

Recommended Posts

Hi,

 

I'm working on a small script that creates a tab delimited text file of some information from a database.  Currently the script is supposed to write to a file to create the headings row, then query the database for some information, and append that information to the headings row.  It appends to the file three different times before reaching the end of the script.

 

It works perfectly on my local machine, but after moving it to the server, I am getting a file open error.

 

Here is the initial part that creates the headings:

 

//prepare new export.txt for writing
$myFile = "/pathtofile/export.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$headerData = "CODE\tNAME\tCATEGORIES\tATTRIBUTE_CODE\tATTRIBUTE_NAME\tOPTION_CODE\tOPTION_NAME\tPRICE\tCOST\tWEIGHT\tTAXABLE\n";
fwrite ($fh, $headerData);
chmod('/pathtofile/export.txt', 0777);
fclose($fh);

 

It creates the file, with the headings, and the file permissions according to my ftp client are set to 777.  However, when I try to open it to append the next set of data, I get an error.

 

//open export.txt and append product data
$myFile = "export.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = $proddata['code'] . "\t"
	. $proddata['name'] . "\t"
	. $categories . "\t"
	. "\t\t\t\t"
	. $price . "\t"
	. $proddata['cost'] . "\t"
	. $proddata['weight'] . "\t"
	. $proddata['taxable'] . "\n";
fwrite($fh, $stringData);
fclose($fh);

}

 

I would appreciate any suggestions for what I may be doing wrong.  As I said, it works perfectly on my local machine, so I'm assuming it's some sort of permissions problem???

Link to comment
https://forums.phpfreaks.com/topic/127023-solved-unable-to-open-file-to-append/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.