0

I'm looking at changing our current intranet, which works with RTF files, so that it can work with docx.

We need to be able to change the templates, and after that inject it with some data from the intranet, and save it as a docx file.

For that I found TinyButStrong plugin, and it seems to be able to do, what we want.

I have done some tests, and can get it to save a file in the same folder as the template. But I can't get it to save in another location.

It gives me this error:

TinyButStrong Error OpenTBS Plugin: Method Flush() cannot overwrite the target file '//SERVER/SHARE/FOLDER/SUBFOLDER/ANOTHER SUBFOLDER/document name.docx'. This may not be a valid file path or the file may be locked by another process or because of a denied permission. The process is ending, unless you set NoErr property to true.

I don't think it's a premission error, cause I working in the same script which is working with our RTF files, and they get saved at the same location, as I need this to do.

But I'm sure it's just me, that doesn't understand TinyButStrong the right way, so how do I make it save on dynamic file path?

The following is where I try to handle the dynamical file path.

        $file = "//$SERVER/$KATALOG/".$_GET['type'].$root.$nr."/"; //.$_GET['type'].$nr."R".$rev."-".$sprog.".rtf"; 


    //echo $template;
    $output_file_name = str_replace('.', '_'.date('Y-m-d').$save_as.'.', $filename); 
    echo $output_file_name = $file . $output_file_name;
    if ($save_as==='') { 
        // Output the result as a downloadable file (only streaming, no data saved in the server) 
        $TBS->Show(OPENTBS_DOWNLOAD, $output_file_name); // Also merges all [onshow] automatic fields. 
        // Be sure that no more output is done, otherwise the download file is corrupted with extra data. 
        exit(); 
    } else { 
        // Output the result as a file on the server. 
        $TBS->Show(OPENTBS_FILE, $output_file_name); // Also merges all [onshow] automatic fields. 
        // The script can continue. 
        exit("File [$output_file_name] has been created."); 
    } 
Skrol29
  • 5,402
  • 1
  • 20
  • 25

2 Answers2

0

It seems you're using the OpenTBS plug-in for TinyButStrong.

OpenTBS simply uses the PHP function fopen($File, 'w') when writing the target file.

The error message you've got indicates that PHP has failed to open an handle for this file in write mode. The raisons may be various, but you can check yourself with the file path you've mentioned.

Skrol29
  • 5,402
  • 1
  • 20
  • 25
  • Yes, I'm using the OpenTBS plug-in, but I can't follow you all the way. I have this piece of code, which is working. if ($diverse != "forkal"){ $fp = fopen($file, 'w'); fputs($fp, $output); fclose($fp); } Basicly I'm trying to get rid of that, and use OpenTBS instead But I'm guesing that the output_file_name, I'm providing is wrong somehow – Lars Sørensen Jun 28 '17 at 10:02
  • For a robust debugging, try your snippet `$fp = fopen($file, 'w')` just before the `$TBS->Show(OPENTBS_FILE, $output_file_name)` and with with the same variable `$output_file_name`. – Skrol29 Jun 28 '17 at 13:35
  • What do you have if you insert the line `$fp = fopen($output_file_name, 'w'); fwrite($fp, "hello"); fclose($fp); exit "ok";` juste before the line `$TBS->Show(OPENTBS_FILE, $output_file_name)` ? Do you have the expected file and output text ? – Skrol29 Jun 28 '17 at 15:40
  • If I insert $fp = fopen($output_file_name, 'w'); fwrite($fp, "hello"); fclose($fp); exit ("ok"); It will output "ok", but not a file – Lars Sørensen Jun 30 '17 at 13:27
  • This result shows that no PHP is able to write the file $output_file_name. You have to solve this in order to have your TBS merging result. – Skrol29 Jul 04 '17 at 00:26
  • But how do I work that out? If I output the path it is the right path. Could understand it, if the path was wrong, and if I wasn't able to create the file as the same location as the template. – Lars Sørensen Jul 11 '17 at 13:15
  • Your problem is now how to debug a PHP error. You understand that lot of many reasons can happen. First check the result of the function `fwrite($fp, "hello")`. Then also check why there no PHP notice or PHP error message. If fwrite() failed then there should have an error. – Skrol29 Jul 12 '17 at 13:12
-1

I have the same error just like you with OPENTBS and in my case, it's very simple that i forgot to create the directory folder to store output file

Tornado
  • 1
  • 1