Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.