I tried to create new file/folder programmatically inside Drupal's sites/default/files. But I'm getting this error: "Can't Open file".
Here is what I'm doing: When my registered user visits a certain page, I will be generating a new file and I will provide them with the download link. When I tried to create a new file I am getting "can't open file" message. I'm in localhost in MS Windows.
Are there any other writable folder other than sites/default/files for doing this stuff?
Below is my code:
$ourFileName = base_path()."/sites/default/files/members-pdf/testFile.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fclose($ourFileHandle);
Above code is written inside a views's template file.
I want to use PHP file API and not Drupal 7 file API.
base_path()."/sites/default/files/members-pdf/testFile.txt"
doesn't seem right, because base_path() will at least return a single slash. Try ifbase_path()."sites/default/files/members-pdf/testFile.txt"
works better.$ourFileName = $_SERVER['DOCUMENT_ROOT'] . '/sites/default/files/members-pdf/testFile.txt';
should work fine assuming your web server can write to that folder, and your Drupal installation is in the web root (not in a sub-folder)