2

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);
save_csv_file($csv_text);


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


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];

    save_inventory_defaults($default_vals);
}

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;
   }
   ob_start();
   $df = fopen("php://output", 'w');
   fputcsv($df, array_keys(reset($array)));
   foreach ($array as $row) {
      fputcsv($df, $row);
   }
   fclose($df);
   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
1

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

http://helpdesk.getpantheon.com/customer/portal/articles/745361-known-limitations

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

| improve this answer | |
0

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.

| improve this answer | |

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.