FIXED DaDaBIK 12.0, images not printed in PDF

eugenio

Administrator
Staff member
Hi,
in DaDaBIK 12, with the upgrade of the TCPDF library, images are not printed anymore in PDF. To fix this, edit the file /include/tcpdf/tcpdf.php

replace line 6970, that contains:

PHP:
return false;

with:

PHP:
// start DaDaBIK MOD
//return false;
// end DaDaBIK MOD

replace line 6975, that contains:

PHP:
$imgdata = $this->getCachedFileContents($file);

with

PHP:
// start DaDaBIK MOD
//$imgdata = $this->getCachedFileContents($file);
$opts = array( 'http'=>array( 'method'=>"GET",'header'=>"Accept-language: en\r\nCookie: ".session_name()."=".session_id()."\r\n" ) );
$context = stream_context_create($opts);
session_write_close();   // this is the key
global $site_url;
if ($site_url === ''){
    $site_url = "http".(isset($_SERVER['HTTPS']) ? 's' : ''). '://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/';
}
$file = $site_url.$file;
$imgdata = file_get_contents($file, false, $context);
if ($imgdata === false || is_null($imgdata)){
    return false;
}
// end DaDaBIK MOD
 

Dano

New member
When I generate PDF's using the default "No PDF template" the image is not being added to the result PDF. There is just a blank space where the image should be. The images are jpg stored in /uploads folder and they look fine in my form page.

I applied the above TCPDF fix, but still no jpg images are showing up in the PDF.

Your current DaDaBIK version​

You are using DaDaBIK version 12.0-Aveto enterprise, installed on 05-21-2024 (installation code: 19645664d1cb140ec7), the latest version of DaDaBIK is 12.0-Aveto released on 05-08-2024

You are running the latest release of DaDaBIK

In case you want to upgrade to a more powerful edition (from Pro to Enterprise/Platinum, from Enterprise to Platinum) please contact us.
System info

PHP Version: 8.2.19

mysql version: 10.3.39-MariaDB-0+deb10u2

Web server: Apache

Client: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36

URL installation: https://database...
 

eugenio

Administrator
Staff member
Hello,
could you check in your error logs if you see any PHP error?
Please also double check if the fix has been correctly applied.
Here you can find an old related post:
 

Dano

New member
Ok, yes I do get an error which seems to be related to permissions. I'm pretty sure the fix was applied correctly.

I replaced my dadabik domain in the error with "my_dadabik_domain"
I replaced my dadabik database in the error with "my_dadabik_database"

[Tue May 28 17:40:18.108588 2024] [proxy_fcgi:error] [pid 20196:tid 140404192163584] [client 2600:8802:2a0b:b100:e9fe:ebfe:bb2d:936b:0] AH01071: Got error 'PHP message: PHP Warning: file_get_contents(https://my_dadabik_domain/index.php?r=1716918017&function=show_file&file_type=image_file&tablename=my_dadabik_database&tablename_original=my_dadabik_database&file_field_name=thumb_file&master_table_name=&is_items_table=0&where_field=serial&where_value=2): Failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized\r\n in /var/www/vhosts/my_dadabik_domain/include/tcpdf/tcpdf.php on line 6987', referer: https://my_dadabik_domain/index.php?tablename=my_dadabik_database&function=details&where_field=serial&where_value=2
 

eugenio

Administrator
Staff member
Ok, yes I do get an error which seems to be related to permissions. I'm pretty sure the fix was applied correctly.

I replaced my dadabik domain in the error with "my_dadabik_domain"
I replaced my dadabik database in the error with "my_dadabik_database"

[Tue May 28 17:40:18.108588 2024] [proxy_fcgi:error] [pid 20196:tid 140404192163584] [client 2600:8802:2a0b:b100:e9fe:ebfe:bb2d:936b:0] AH01071: Got error 'PHP message: PHP Warning: file_get_contents(https://my_dadabik_domain/index.php?r=1716918017&function=show_file&file_type=image_file&tablename=my_dadabik_database&tablename_original=my_dadabik_database&file_field_name=thumb_file&master_table_name=&is_items_table=0&where_field=serial&where_value=2): Failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized\r\n in /var/www/vhosts/my_dadabik_domain/include/tcpdf/tcpdf.php on line 6987', referer: https://my_dadabik_domain/index.php?tablename=my_dadabik_database&function=details&where_field=serial&where_value=2

If you open with your browser the URL

https://my_dadabik_domain/index.php?r=1716918017&function=show_file&file_type=image_file&tablename=my_dadabik_database&tablename_original=my_dadabik_database&file_field_name=thumb_file&master_table_name=&is_items_table=0&where_field=serial&where_value=2

does it work?
 

Dano

New member
Yes, that URL works - it just takes me to my Dadabik home page. It doesn't do anything else.
 

Dano

New member
I am using directory password protection for my Dadabik folders so that might have something to with the PDF not working

Based on this error in the access_ssl_log I don't think the URL is working

[29/May/2024:21:22:09 +0000] "GET /my_dadabik_folder/index.php?r=1716918017&function=show_file&file_type=image_file&tablename=my_database&tablename_original=my_database&file_field_name=thumb_file&master_table_name=&is_items_table=0&where_field=serial&where_value=2 HTTP/1.0" 302 1089 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"

2600:8802:2a0b:b100:458e:7870:7fda:3274 - arty [29/May/2024:21:22:09 +0000] "GET /my_dadabik_folder/index.php?function=show_static_page&id_static_page=1 HTTP/1.0" 200 11538 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"

This error in error_log:

[Wed May 29 21:45:13.689360 2024] [proxy_fcgi:error] [pid 9594:tid 140403529467648] [client 98.63.240.157:0] AH01071: Got error 'PHP message: PHP Warning: readfile(/var/www/vhosts/my_dadabik_domain/uploads/03475_thumb.jpg): Failed to open stream: No such file or directory in /var/www/vhosts/my_dadabik_domain/front_logic.php on line 0', referer: https://my_dadabik_domain/index.php?tablename=my_dadabik_database&function=search&order=serial&order_type=DESC&page=0
 
Last edited:

Dano

New member
Same result after fixing &amp with &. It doesn't show the image, just goes to the home page.

This is the error in access_ssl_log

2600:8802:2a0b:b100:294c:fb33:2701:3439 - arty [30/May/2024:16:08:56 +0000] "GET /my_dadabik_folder/index.php?r=1716918017&;function=show_file&;file_type=image_file&;tablename=my_dadabik_database&;tablename_original=my_dadabik_database&;file_field_name=thumb_file&;master_table_name=&;is_items_table=0&;where_field=serial&;where_value=2 HTTP/1.0" 302 1089 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"

2600:8802:2a0b:b100:294c:fb33:2701:3439 - arty [30/May/2024:16:08:56 +0000] "GET /my_dadabik_folder/index.php?function=show_static_page&id_static_page=1 HTTP/1.0" 200 11538 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
 

eugenio

Administrator
Staff member
the url is not correct, you have to replace & with &, it seems you have replaced &amp with &
 

Dano

New member
Ahhh, syntax doesn't forgive. Still same, doesn't display image, just goes to home page.

Access_ssl_log

2600:8802:2a0b:b100:4474:a2f6:120f:f135 - arty [31/May/2024:17:44:30 +0000] "GET /my_dadabik_folder/index.php?r=1716918017&,function=show_file&,file_type=image_file&,tablename=my_dadabik_database&,tablename_original=my_dadabik_database&,file_field_name=thumb_file&,my_dadabik_database=&,is_items_table=0&,where_field=serial&,where_value=2 HTTP/1.0" 302 1089 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"

2600:8802:2a0b:b100:4474:a2f6:120f:f135 - arty [31/May/2024:17:44:30 +0000] "GET /my_dadabik_folder/index.php?function=show_static_page&id_static_page=1 HTTP/1.0" 200 11538 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
 

Dano

New member
Syntax is killing me... Ok, yes the image now displays on the browser screen with this URL:

https://my_database_domain/index.php?r=1716918017&function=show_file&file_type=image_file&tablename=my_database&tablename_original=my_database&file_field_name=thumb_file&my_database=&is_items_table=0&where_field=serial&where_value=2
 

eugenio

Administrator
Staff member
If the URL works from the browser, there is some permissions-related issue that don't allow your PHP to open such url using
file_get_contents, check this with your hosting provider. I doubt this is related to V12 and the bug reported here.
 

Dano

New member
Ok thank you for all the help. I will investigate server permissions. I love DaDBIK and it's working great for us.
 
Top