Jump to content

save pdf to server


ootweb

Recommended Posts

PHP Newbie here,

I have a flex app that iam using alivepdf to create a pdf document the current code below allows the user to download the pdf file, i would also like to upload the same pdf to the server is this possible?

 

Cheers

B

 

1.<?php
2. 
3.$method = $_GET['method'];
4.$name = $_GET['name'];
5. 
6.if ( isset ( $GLOBALS["HTTP_RAW_POST_DATA"] )) {
7.    
8.    // get bytearray
9.    $pdf = $GLOBALS["HTTP_RAW_POST_DATA"];
10.    
11.    // add headers for download dialog-box
12.    header('Content-Type: application/pdf');
13.    header('Content-Length: '.strlen($pdf));
14.    header('Content-disposition:'.$method.'; filename="'.$name.'"');
15.    echo $pdf;
16.    
17.}  else echo 'An error occured.';
18. 
19.?>

Link to comment
https://forums.phpfreaks.com/topic/165733-save-pdf-to-server/
Share on other sites

Hi there, the answer to your question is quite simple, since you've already got it half figured out

 

First, you need to create a $Path Variable containing the path to your save location on your server to execute the code I'm about to show you. The code that you have only makes it available for download by showing it in a pdf page.

 

<?php
$handle = fopen($Path, "w");
fwrite($handle, $pdf);
fclose($handle);	
?>

 

You should add these 3 lines (without the <?php and ?> brackets) before line 11 of your program, and everything should go fine if you've set your $Path variable correctly. Took me a while to figure out too  :D

Link to comment
https://forums.phpfreaks.com/topic/165733-save-pdf-to-server/#findComment-875155
Share on other sites

thanks for the reply

the .php file was taken from the alivepdf sample so i did not write it

 

this does not work?

 

<?php

$method = $_GET['method'];
$name = $_GET['name'];
$path = "save/";

if ( isset ( $GLOBALS["HTTP_RAW_POST_DATA"] )) {

$handle = fopen($Path, "w");
fwrite($handle, $pdf);
fclose($handle);

// get bytearray
$pdf = $GLOBALS["HTTP_RAW_POST_DATA"];

// add headers for download dialog-box
header('Content-Type: application/pdf');
header('Content-Length: '.strlen($pdf));
header('Content-disposition:'.$method.'; filename="'.$name.'"');
echo $pdf;

}  else echo 'An error occured.';

?>

]

Link to comment
https://forums.phpfreaks.com/topic/165733-save-pdf-to-server/#findComment-875511
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.