Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
i use Printer, e-mail and PDF versions(tcpdf) to generate pdf file, the pdf file generate very well in my localhost, but when i copy it to my sandbox, it won't appear. it show a error message like this
"TCPDF ERROR: [Image] No such file or directory in http://www.example.com/sites/all/themes/example/logo.png"
i have double checked the path, logo.png is still there, i don't do something wrong i guess
i tried
http://drupal.org/node/314521 and http://drupal.org/node/337798 but it didn't help me to solve this problem
can someone help me for this problem?
Comments
Comment #1
jcnventura CreditAttribution: jcnventura commentedYour server is probably not authorized to access itself..
Comment #2
paradise7777 CreditAttribution: paradise7777 commentedhi João,
i tried to authorized it, i use chmod 777 but nothing changed,
any other solution João?
Comment #3
jcnventura CreditAttribution: jcnventura commentedIt's not the file access rights. The Web server is unable somehow to access an URL in itself.. It can be an apache setting or DNS configuration, or a firewall setting.
Comment #4
jcnventura CreditAttribution: jcnventura commentedComment #5
paradise7777 CreditAttribution: paradise7777 commentedafter i try what you said and then i try the printer friendly, i used http://www.example.com/?q=print/book/export/html/225 the display for printer friendly appear, but when i want to display the pdf version it turn into the same error again, i used http://www.example.com/?q=printpdf/book/export/html/225 is it the TCPDF?
what shoud i do to handle this?
Comment #6
jcnventura CreditAttribution: jcnventura commentedWhen you (your browser) accesses the print-friendly page, it's coming from outside the server.
When TCPDF accesses the page, it's coming from inside the server. Check your logs to see when/why it's denying access to that file.
João
Comment #7
paradise7777 CreditAttribution: paradise7777 commentedgetimagesize(http://www.example.com/logo.png) [function.getimagesize]: failed to open stream: HTTP request failed! HTTP/1.1 401 Authorization Required in /hermes/web10/b930/hoc.example/example-projects/example/sites/all/modules/print/print_pdf/print_pdf.pages.inc on line 393.
in line 393 : $size = getimagesize($logo);
i have change the $logo into :
$size = getimagesize('http://www.example.com/sites/all/themes/example/logo.png');
but it'doesn't effect. and then i tried to use cURL,
i put this function in print_pdf.pages.inc
function remote_filesize ($url, $user='web', $pass='user') {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, "$user:$pass");
$data = curl_exec($ch);
curl_close($ch);
$filename = "temp." . time();
$fp = @fopen($filename, "w+");
fwrite($fp, $data);
fclose($fp);
$info = getimagesize($filename);
@unlink($filename);
return $info;
}
and then i put this code inside the print_pdf.pages.inc
i replace $size = getimagesize($logo); with
$size = remote_filesize("http://".$_SERVER['HTTP_HOST']."/logo.png);
but still error, what should i do?
Comment #8
jcnventura CreditAttribution: jcnventura commentedI have repeated this too many times: Your server is not authorized to access itself. Figure it out in your server/network/firewall configuration.
There's nothing the module can do to change that. I am closing this, as I'd prefer if you stopped wasting my time. Please read what I have written 3-4 times now and start figuring out how to solve your problem.
João
Comment #9
paradise7777 CreditAttribution: paradise7777 commentedokay, João
thanks for your help and i'm sorry to wasting your time
Comment #10
celideo CreditAttribution: celideo commentedJust add:
allow_url_fopen = On;
allow_url_include = On;
to php.ini... not so hard.
Comment #11
mdriess CreditAttribution: mdriess commentedMaybe this comment is important for those gyus who do have still the problem: If you have an Apache authentification (e.g. because you don't want to let see the content before it is ready) this behaviour is normal and cause on the authentification.
Comment #12
kndrThanks mdriess! "this behaviour is normal and cause on the authentification" - exactly!
Comment #13
jordannoel CreditAttribution: jordannoel commentedIs there any solution for drupal 6.15?
Comment #14
timezero CreditAttribution: timezero commentedadding
allow_url_fopen = On;
allow_url_include = On;
to php.ini in the drupal folder (create it if it's no there) solved it for me.
Comment #15
Jonasvh CreditAttribution: Jonasvh commentedi had the same problem because the url of my site was without WWW
When i go to my site with WWW on the front of the URL, everthing worked fine.
Comment #16
jcnventura CreditAttribution: jcnventura commentedI guess this issue is also related to #726082: Looks like there's an undocumented dependency in the print_pdf module on allow_url_fopen setting. I've tried to remove the dependency on allow_url_fopen, in the current module versions, so TCPDF may now work slightly better for some of you.
Comment #17
sz___g CreditAttribution: sz___g commentedMaybe wrong path calculation in case of pictures. Try to comment in tcpdf.php like this:
case 'img': {
if(isset($attr['src'])) {
// replace relative path with real server path
if ($attr['src'][0] == '/') {
$attr['src'] = $_SERVER['DOCUMENT_ROOT'].$attr['src'];
}
comment this line -----> // $attr['src'] = str_replace(K_PATH_URL, K_PATH_MAIN, $attr['src']);
if(!isset($attr['width'])) {
This helps the problem below:
Warning: fopen(somewhere//libraries/something.png) [function.fopen]: failed to open stream: No such file or directory in /libraries/tcpdf/tcpdf.php on line 3717
TCPDF error: Can't open image file: somewhere//libraries/something.png