1 (edited by diigiit 04/13/2018 08:24:54 pm)

Topic: Failed to load PDF document

Hello,
This is a very weird bug and still try to understand it. Hope someone can help.
I was working on company accounting adding journal entries and attaching PDF file for each invoice entered. Frontaccounting is online. Everything was working ok (in fact it is working since months). Was able to attach and see PDF invoices in Frontaccounting.
Suddenly, with no reason, PDF attachments stopped working with error message "Failed to load PDF document".
Release number is 2.3.22.
I first suspected a corrupted attached file or a browser issue. The problem is the same whether I am using Firefox or Chrome.
The weird thing is that the problem is the same on any other computer including the one that are using a local database and installation.
After investigation, it looks like the problem is located inside /admin/attachments.php
The piece of code
echo file_get_contents(company_path(). "/attachments/".$row['unique_name']);
point to a non existing file; $row['unique_name'] return unique_name found on 0_attachments table for the file but this file does not exists under company/0/attachments/ repository.
Backups files shows exactly the same thing.
How attached file are stored?

Re: Failed to load PDF document

Was able to solve the problem. Actually, for some reason, permission on attachments repository was changed. Add the +rw permission. Solved my problem.

Re: Failed to load PDF document

Dears,

Not the same problem but deleting an attachment from frontaccounting interface does not delete it from the company/x/attachment folder. Is this how it should be?

Re: Failed to load PDF document

The document stands delinked from the transaction. Manually delete it physically if it is a permissions issue. It is possible that one may want to link it to another transaction otherwise.

The code for deletion is in lines 145 to 154 in  admin/attachments.php:

if ($Mode == 'Delete')
{
    $row = get_attachment($selected_id);
    $dir =  company_path()."/attachments";
    if (file_exists($dir."/".$row['unique_name']))
        unlink($dir."/".$row['unique_name']);
    delete_attachment($selected_id);    
    display_notification(_("Attachment has been deleted.")); 
    $Mode = 'RESET';
}

The unlink statement clearly is supposed to delete the file.