I am trying to write files and read from them. The following code works great on my local Kalabox server, but when I push to Pantheon, the files don't get written.

Could it be because all files are under sub versioning on Pantheon?

$csv_text = array2csv($db_result);

if($_GET[save_to_email] == 'true'){

function save_csv_file( $csv_text){
    //$file = './inventory.csv';
    $file = 'public://inventory.csv';
    file_put_contents($file, $csv_text);

function save_defaults(){
    $default_vals = get_inventory_defaults();
    $default_vals[sort_direction] = $_GET[sort_direction];
    $default_vals[threshold] = $_GET[threshold];
    $default_vals[hide_zero_inventory] = $_GET[hide_zero_inventory];
    $default_vals[email] = $_GET[email];


function get_inventory_defaults(){
    $file = './inventory_defaults.txt';
    //$file = 'public://inventory_defaults.txt';
    $content = unserialize(file_get_contents($file));
    return $content;

function save_inventory_defaults($my_variable){
    //$file = './inventory_defaults.txt';
    $file = 'public://inventory_defaults.txt';
    $content = serialize($my_variable);
    file_put_contents($file, $content);
    //file_save_data($content, $file, FILE_EXISTS_RENAME );

function array2csv(array &$array)
   if (count($array) == 0) {
     return null;
   $df = fopen("php://output", 'w');
   fputcsv($df, array_keys(reset($array)));
   foreach ($array as $row) {
      fputcsv($df, $row);
   return ob_get_clean();

I am not sure when to go from here... A million thanks!!

  • Potentially silly question, but is the file TAXONOMY_MENU.DATABASE.INC where it expects to find it?
    – Gold
    Sep 23 '14 at 20:58
  • Yes, same folder as TAXONOMY_MENU.MODULE
    – Bryan
    Sep 23 '14 at 20:59
  • Solved this taxonomy issue by requiring inc files instead of doing buutstrap_full
    – Bryan
    Sep 23 '14 at 23:06

From Pantheon docs: "Pantheon cannot be used to host files over 256MB, no matter how the file is uploaded"


It could be that your file is too large and therefore Pantheon will not host it.


I would suggest you to check the server permission for writing the files, if the permissions are properly given then you can try giving the exact relative path (which would be something like DRUPAL_ROOT . "/sites/default/files") instead of just "public://".

If that doesn't work then you can try cURL to read and write the contents of file instead of using file_get_contents and file_put_contents.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.