<?php

function fwrite_stream($fp, $string) {
    for ($written = 0; $written < strlen($string); $written += $fwrite) {
        $fwrite = fwrite($fp, substr($string, $written));
        if (!$fwrite) {
            return $fwrite;
        }
    }
    return $written;
}

$method = $_GET['method'];
$name = $_GET['name'];

if ( isset ( $GLOBALS["HTTP_RAW_POST_DATA"] )) {
	
	// 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; */
	$fileName = time();
	$filePath = "../design_pdfs/$fileName.pdf";
	$fp = fopen($filePath, 'w');
	fwrite($fp, $pdf);
	fclose($fp);
	
	echo "Thanks for designing your card with Smashhit Solutions online Design center. <a href='$filePath'>Download</a> the PDF";
	
}  else echo 'An error occured.';

?>