Best Location to Create a File

Permalink
Hi, what is the best location to create an automatically generated PHP file? Please keep in that this is in a package that I plan to sell in the marketplace. I want to have it create a folder and then a PHP file within that new folder. Where should I put it? (packages/PACKAGE_NAME/*) or (C5 HOME DIR/*)

Thanks

celwell
 
12345j replied on at Permalink Reply
12345j
for your package it is best to put it in packages/package_name/ because this will allow for easier uninstallation
celwell replied on at Permalink Reply
celwell
Ok, I was having problems with that. Are there any permissions problems with doing that?

(I'm not sure why it wasn't working. It worked for the c5 home dir.)
12345j replied on at Permalink Reply
12345j
whats your code and what r u trying to do?
celwell replied on at Permalink Reply
celwell
i have this in a block controller that's in a package:
$myFile = $data['bID'] . '_Form.php';
   $fh = fopen($myFile, 'w');
   fwrite($fh, "test");
   fclose($fh);

which works,
but when I try to do something like:
$myFile = 'packages/blahblah/newfoldername/' . $data['bID'] . '_Form.php';

it fails.
Maybe it's because I'm trying to create a new folder with "w" and not "w+"?
12345j replied on at Permalink Reply
12345j
maybe, im not really on expert on that type of things. Can you try creating that folder and then seeing if it works? also, it try using a path like /packages/blahblah in $myFile variable- that might fix it also, but I just guessing.
jordanlev replied on at Permalink Best Answer Reply
jordanlev
It is most likely a permissions issue. And you can't set file/directory permissions from code (which is good, because it presents an insane security risk). You will have to either instruct users of your package to manually give the web server write permissions on your package directory after installation, or hook into the c5 file manager instead (which would require a lot more code on your part, and it's not very documented -- you'd have to read through the c5 code to see how it's done -- check out concrete/libraries/file/importer.php for examples I think).