7

I'm working with fpdf libray for providing pdf files. A part of my project consists of using this library to generate pdf files for consumers. We are working with a server test under "ovh". The arborescence of my space in "ovh" is : /www/betatest.

A folder named upload which contains factures's folder where all the facture's pdf files will be there. So, when i try to generate a pdf file inside the factures folder, in a web browser it displays me :

Warning: fopen(upload/factures/facture_98.pdf) [function.fopen]: failed to open stream: Success in /homez.742/coplayer/www/betatest/library/fpdf/fpdf.php on line 1025

FPDF error: Unable to create output file: upload/factures/facture_98.pdf.

I tried a lot of things that i found in this web site but does not work. Please help me. Thank's a lot! :)

user2567806
  • 460
  • 3
  • 7
  • 17

3 Answers3

6

Make sure the directory have at least a 755. Also, use $_SERVER['DOCUMENT_ROOT'] with your path to target the good directory :

$nomFacture = $_SERVER['DOCUMENT_ROOT']."upload/factures/facture_".$idFacture.".pdf";

That will produce something like

/homez.742/coplayer/www/betatest/upload/factures/facture_12.pdf

Brewal
  • 8,067
  • 2
  • 24
  • 37
  • Warning: fopen(/homez.742/coplayer/www/betatest/upload/factures/facture_114.pdf) [function.fopen]: failed to open stream: Success in /homez.742/coplayer/www/betatest/library/fpdf/fpdf.php on line 1025 FPDF error: Unable to create output file: /homez.742/coplayer/www/betatest/upload/factures/facture_114.pdf – user2567806 Aug 30 '13 at 08:22
  • Even with making the directory 755 – user2567806 Aug 30 '13 at 08:38
  • @user2567806 do you have any documentation of your "pdf" class ? It could be outputing this because you don't open the file with `w+` (read and write) – Brewal Aug 30 '13 at 08:45
  • i'm using the fpdf class that we can found in this web site : http://www.fpdf.org/, that can be donwloaded freely – user2567806 Aug 30 '13 at 09:03
  • Ok you will need to try modifying the file `fpdf.php`. At the line 1025 you have `$f = fopen($name,'wb');`. Change this to `$f = fopen($name,'w+');` – Brewal Aug 30 '13 at 09:35
  • 1
    If this didn't work, it could be a "safe mode" issue with ovh. Try to see if you have this kind of option you could disable. If not, try removing the "factures" directory and make it with the php script : `mkdir($_SERVER['DOCUMENT_ROOT']."upload/factures/", 0777);` – Brewal Aug 30 '13 at 09:40
  • I modified the parameter of the fopen function inside the fpdf.php but a got the same message again – user2567806 Aug 30 '13 at 09:40
  • @user2567806 Then undo the changes in this file. – Brewal Aug 30 '13 at 09:41
  • i did it but i have the same error message, localy with wampserver it works well ! – user2567806 Aug 30 '13 at 10:02
  • Output a `phpinfo();` and find the line with `safe_mode`. Is it "off" ? – Brewal Aug 30 '13 at 10:11
  • - Brewal : yes i found that safe_mode is off, do i need to change it ? – user2567806 Aug 30 '13 at 13:16
  • @user2567806 No it should be off. Sorry I think I tried everything I can on this one. Hope someone else with other ideas will help you. – Brewal Aug 30 '13 at 13:39
  • Thank you so much for spending times for this -Brewal. Please do you know other libraries that can i use for generating pdf files ? – user2567806 Aug 30 '13 at 13:45
  • I have good echoes of [`Zend_Pdf`](http://framework.zend.com/manual/1.12/fr/zend.pdf.html). I assume you are french ? :) – Brewal Aug 30 '13 at 14:05
  • Oui Brewal ;). Merci pour le lien. – user2567806 Aug 30 '13 at 14:06
  • But i need to install the framework and i'm working with CakePHP, i won't to change the framework for a library it is constrainting. – user2567806 Aug 30 '13 at 14:14
  • It should not be a problem. You should take a look at this : [How to use Zend Framework in CakePHP](http://cakephptips.blogspot.fr/2008/03/howto-use-zend-framework-in-cakephp_7464.html). Or [This](http://bakery.cakephp.org/articles/kalileo/2010/06/08/creating-pdf-files-with-cakephp-and-tcpdf) ! – Brewal Aug 30 '13 at 14:17
2

Make sure you have not sending to output something else (like echo, var_dump, etc.) before generating PDF with Output("path_file", "F"). It is mandatory.

Alessio Cantarella
  • 5,077
  • 3
  • 27
  • 34
Ovi Mag
  • 21
  • 2
-1

make sure that file upload/factures/facture_98.pdf is not open anywhere when you run script. if it's open somewhere else then TCPDF can't open it.

Divyesh Jesadiya
  • 1,105
  • 4
  • 30
  • 68