Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Closed Thread
How I can save a PDF file to a directory
Old 02-14-2006, 05:32 AM How I can save a PDF file to a directory
Super Talker

Posts: 145
Trades: 0
Hello everyone,

I have a question regarding the PDF files.I have written the code in order to open a PDF, i manage to output the context in the browser but i want also this PDF file to be saved in a directory.

Does anyone know how i will do it?

I can post the code if you think this will be helpful for you.

Thank you in advance,
Xenia
xenia is offline
View Public Profile
 
 
Register now for full access!
Old 02-14-2006, 06:11 AM Re: How I can save a PDF file to a directory
digitalfields's Avatar
Skilled Talker

Posts: 50
Trades: 0
What about using the copy function?

http://uk.php.net/copy
__________________
Digital Fields - Web Design

Please login or register to view this content. Registration is FREE
digitalfields is offline
View Public Profile Visit digitalfields's homepage!
 
Old 02-14-2006, 06:38 AM Re: How I can save a PDF file to a directory
Super Talker

Posts: 145
Trades: 0
Thank you digitalfields for your suggestion but i tryied and nothing happen.
I think there is a command which redirectes the PDF file to both the browser and in a directory. In order to display the context of it i use the command

PHP Code:
$pdf -> output(); 
where $pdf is the creation of the pdf file.

Any other suggestins?
xenia is offline
View Public Profile
 
Old 02-14-2006, 07:14 AM Re: How I can save a PDF file to a directory
Super Talker

Posts: 145
Trades: 0
I am using the class "fpdf.php" and all the functions are stored to that file.
So i have a function called
PHP Code:
function Output($name='',$dest='')
{
        
//Output PDF to some destination
        //Finish document if necessary
        
if($this->state<3)
                
$this->Close();
        
//Normalize parameters
        
if(is_bool($dest))
                
$dest=$dest 'D' 'F';
        
$dest=strtoupper($dest);
        if(
$dest=='')
        {
                if(
$name=='')
                {
                        
$name='doc.pdf';
                        
$dest='I';
                }
                else
                        
$dest='F';
        }
        switch(
$dest)
        {
                case 
'I':
                        
//Send to standard output
                        
if(ob_get_contents())
                                
$this->Error('Some data has already been output, can\'t send PDF file');
                        if(
php_sapi_name()!='cli')
                        {
                                
//We send to a browser
                                
header('Content-Type: application/pdf');
                                if(
headers_sent())
                                        
$this->Error('Some data has already been output to browser, can\'t send PDF file');
                                
header('Content-Length: '.strlen($this->buffer));
                                
header('Content-disposition: inline; filename="'.$name.'"');
                        }
                        echo 
$this->buffer;
                        break;
                case 
'D':
                        
//Download file
                        
if(ob_get_contents())
                                
$this->Error('Some data has already been output, can\'t send PDF file');
                        if(isset(
$_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'],'MSIE'))
                                
header('Content-Type: application/force-download');
 else
                                
header('Content-Type: application/octet-stream');
                        if(
headers_sent())
                                
$this->Error('Some data has already been output to browser, can\'t send PDF file');
                        
header('Content-Length: '.strlen($this->buffer));
                        
header('Content-disposition: attachment; filename="'.$name.'"');
                        echo 
$this->buffer;
                        break;
                case 
'F':
                        
//Save to local file
                        
$f=fopen($name,'wb');
                        if(!
$f)
                                
$this->Error('Unable to create output file: '.$name);
                        
fwrite($f,$this->buffer,strlen($this->buffer));
                        
fclose($f);
                        break;
                case 
'S':
                        
//Return as a string
                        
return $this->buffer;
                default:
                        
$this->Error('Incorrect output destination: '.$dest);
        }
        return 
'';

so in my case i put
PHP Code:
$pdf -> Output($filename,$dir);
$dir='C:\Documents and Settings\My Documents\php';
$filename "Invoicelist_"
So maybe the error is how i out the parameters. It might be too easy the error but maybe i am too tired to find out.

Can you suggest anything?

Thanks again,
Xenia
xenia is offline
View Public Profile
 
Old 02-14-2006, 08:03 AM Re: How I can save a PDF file to a directory
digitalfields's Avatar
Skilled Talker

Posts: 50
Trades: 0
If you are using FPDF you can do the following to save the file:

PHP Code:
$pdf->Output("filename.pdf","F"); 
Which will save the pdf to a file.
Or:
PHP Code:
 $pdf->Output("filename.pdf","D"); 
Will prompt you to save the file.
__________________
Digital Fields - Web Design

Please login or register to view this content. Registration is FREE
digitalfields is offline
View Public Profile Visit digitalfields's homepage!
 
Old 02-14-2006, 08:13 AM Re: How I can save a PDF file to a directory
digitalfields's Avatar
Skilled Talker

Posts: 50
Trades: 0
Quote:
so in my case i put
PHP Code:
$pdf -> Output($filename,$dir);
$dir='C:\Documents and Settings\My Documents\php';
$filename "Invoicelist_"

Thanks again,
Xenia
Just to add you are misinterpreting $dest in the Output function.

Check http://www.fpdf.org/en/doc/output.htm for more info.

string Output([string name [, string dest]])

dest is a switch which controls the destination where the file will be sent(browser,file,prompt)
__________________
Digital Fields - Web Design

Please login or register to view this content. Registration is FREE
digitalfields is offline
View Public Profile Visit digitalfields's homepage!
 
Old 02-14-2006, 08:16 AM Re: How I can save a PDF file to a directory
Super Talker

Posts: 145
Trades: 0
I used the command you told me but where it suppose to save it?. In which file it save it.I would like to save it to a particular directory ex. "C:\Documents and Settings\My Documents\php"

PHP Code:
$pdf->Output("filename.pdf","F"); 
i wrote this:
PHP Code:
$pdf -> Output("Invoicelist.pdf","D"); 
Sorry that it might be too simple,but i can't understand it.
Could you tell me how to specify in which folder to same this pdf file?

Thanks,
Xenia
xenia is offline
View Public Profile
 
Old 02-14-2006, 08:29 AM Re: How I can save a PDF file to a directory
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
You cannot specify a clientside folder from serverside
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
View Public Profile Visit chrishirst's homepage!
 
Old 02-14-2006, 08:37 AM Re: How I can save a PDF file to a directory
Super Talker

Posts: 145
Trades: 0
Actually this pdf file will be saved to the network to the specific folder.
So not even if it is network cannon be done?

Also if i use the parameter
F: (save to a local file with the name given by name.) where locally saves the file?

Thanks
xenia is offline
View Public Profile
 
Old 02-14-2006, 08:39 AM Re: How I can save a PDF file to a directory
digitalfields's Avatar
Skilled Talker

Posts: 50
Trades: 0
To save it to a folder on the server use
PHP Code:
$pdf->Output("/directory/filename.pdf","F"); 
To save it to a file on your computer:
PHP Code:
$pdf->Output("filename.pdf","D"); 
__________________
Digital Fields - Web Design

Please login or register to view this content. Registration is FREE
digitalfields is offline
View Public Profile Visit digitalfields's homepage!
 
Old 02-14-2006, 09:13 AM Re: How I can save a PDF file to a directory
Super Talker

Posts: 145
Trades: 0
Ok i add the following part of the code as you told me :
PHP Code:
$pdf -> Output("/var/invoices/"."$filename",'F'); 
Unfortunately displays the following error:

"FPDF error: Unable to create output file: /var/invoices/Invoicelist_01_01_2005_14_02_2006"

Do you know where i am making the mistake?
As this error means that it didn't open the file based on the Fpdf class
PHP Code:
                case 'F':
                        
//Save to local file
                        
$f=fopen($name,'wb');
                        if(!
$f)
                        
$this->Error('Unable to create output file: '.$name);
                        
fwrite($f,$this->buffer,strlen($this->buffer));
                        
fclose($f);
                        break; 
Can i also display it on the browser apart from saving?
xenia is offline
View Public Profile
 
Old 02-14-2006, 09:27 AM Re: How I can save a PDF file to a directory
digitalfields's Avatar
Skilled Talker

Posts: 50
Trades: 0
Quote:
Originally Posted by xenia
Unfortunately displays the following error:

"FPDF error: Unable to create output file: /var/invoices/Invoicelist_01_01_2005_14_02_2006"
Is because you are trying to save the file somewhere it doesnt want you to. Most probably because your havent set the permissions of the directory to 777. Also I would add this to the end of your filename.
PHP Code:
$pdf -> Output("/var/invoices/".$filename.".pdf",'F'); 
Quote:
Originally Posted by xenia
Can i also display it on the browser apart from saving?
PHP Code:
$pdf->Output(); 
On its own will display the pdf file in the browser.
__________________
Digital Fields - Web Design

Please login or register to view this content. Registration is FREE
digitalfields is offline
View Public Profile Visit digitalfields's homepage!
 
Old 02-14-2006, 09:43 AM Re: How I can save a PDF file to a directory
Super Talker

Posts: 145
Trades: 0


digitalfields you were right with the permissions i had forgot
to do that.

Thank youuuuuuuuuuuuuuuuuuuuuu
very much for your time and help all of you.

Xenia
xenia is offline
View Public Profile
 
Old 04-25-2006, 05:13 PM Re: How I can save a PDF file to a directory
Junior Talker

Posts: 1
Trades: 0
I have the same problem. But the error message is:

Warning: fopen(gen_pdf/gen_pdf/yan.pdf) [function.fopen]: failed to open stream: No such file or directory in /export/home/.../pdfCov/fpdf.php on line 1698
FPDF error: Unable to create output file: gen_pdf/yan.pdf

I checked the directory "gen_pdf". It is 777.

Anyone know what is wrong?
happykitty is offline
View Public Profile
 
Closed Thread     « Reply to How I can save a PDF file to a directory
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.50412 seconds with 12 queries