Cannot get php generated page to download a a pdf - php

I have a php script that allows you to input your name and then create a certificate, this part works fine but wish the completed certificate to be downloaded as a pdf.
I have searched many forums and sites but cannot figure out how to do this and am very confused and baffled.
The php live test version can be seen at
http://gmdesign.org.uk/xxx/h
Its taken me 4 months to just create that as php is just not my thing and it was 4 month of stress, am asking out of desperation now if someone can add the correct code for me so the certificate downloads as a pdf the code is here:
http://gmdesign.org.uk/xxx/h/script1.zip
when you enter name and proceed then generate certificate it works fine but when you click download the generated pdf is all wrong it does not show your name and also shows rest of page as if its a print out
thanks

If you want to use Dragon's solution, use $_GET variables, example...
At top of your page, place:
$fullName = $_GET['fullname'];
then you can use: hxxp://gmdesign.org.uk/xxx/h/certificate.php?fullname=Full Name
The $fullName var will then be whatever you put in it in the URL.
Example: <? echo($fullName); ?> would echo "Full Name"
Then I think he is saying to then save it on pdfcrowd like "http://gmdesign.org.uk/xxx/h/certificate.php?fullname=Full Name" which will save your certificate template as a PDF with the name "Full Name"
However, if you don't want to use a third party to convert the page to PDF, check out TCPDF like Koen recommended, or look at http://wkhtmltopdf.org

You can use phpToPDF library to create PDF from html file
You have already done coding to generate certificate html file now you have to give that file in phpToPDF libarary so it convert that html to pdf & store it on your server then you have to give that link to download button for download that certificate pdf file..
For phoToPDF library you need API key that you get once you registered with that library.

Related

Use qrencode to generate png/svg QR code for Wireguard client configuration

I am looking to generate a QR code on a PHP webpage. The user starts on a page where they submit a form, the only input being the name of the new client. This page is a manager for VPN clients.
After the redirect, PHP generates the configuration file on the page to copy and paste. The user must save this file as wg.conf in their etc directory. I have been trying to use qrencode, a Linux based command line tool to generate the QR code on that same page with the configuration file. According to the documentation on qrencode, you can save the file as a .png or .svg.
I have been playing around with it, both trying to pass data through the URL as GET parameters in the redirect (the only issue is the QR code is sensitive) and by using the backtick operators to run bash commands to save it as a file in the user's local files. I can't seem to figure out where to save it as a file or whether there's another solution to display it on the webpage.
how i would do it:
check this library https://github.com/neocotic/qrious , all you need to do it load the js on your page
generate text you want to convert to qr code in a text area, div or other HTML element and assign it an id
use that id to extract the data via pure JS, now you have a text variable and you have the possibility to make qr code dynamic now
once you have the data dynamically extracted via JS you can use that variable to generate qr codes like this :
var x = 'sample text'
var qr = window.qr = new QRious({
element: document.getElementById('qrious'),
size: 200,
value: x
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/qrious/4.0.2/qrious.min.js"></script>
<canvas id="qrious">

Downloading an image from php page

So i have this one small thing im doing, and the thing is: It generates QRcodes using the google qrcode api. Id like to download the generated qr code with the press of a button into a /img folder i have inside the folder my php file is located at, and id need it to save with a numerical number which is the button's id. (it has like 120 buttons and each one has a 0-120 id, id like to save the qrcode that belongs to the button 10 with a name like 10.png) any ideas on how to do so?
__
Little edit: as Man Manam pointed out my question is: I have the image link, i want to save it in my server. Sorry for the confusion.
As you're using Google for creating the QR code, I assume you have a code like this somewhere:
$ga = new \Google\Authenticator\GoogleAuthenticator();
$qr_link = $ga->getUrl($username, $_SERVER['HTTP_HOST'], $secret);
// then you'd display that code with <img src="$qr_link">
What you need to do is to simply download that QR code instead of showing in browser. You can use curl for this or, even simpler, just fopen/file_get_contents if allow_url_fopen is set to ON in php.ini
$image_bin = file_get_contents($qr_link);
file_put_contents($target_file_on_filesyste, $image_bin);

Open PDF outside Browser

I'm new to PhP and need some help please
I have the following code to open a Staff member's PDF payslip however when it opens it is easy enough for the User to see the path in the address bar and then be able to manipulate the path to see other people's payslips.
This would however not be possible it the PDF file opened outside the Browser (maybe downloading the file and then opening it in Adobe or so).
(There is a login procedure before it gets to this code)
Can someone help with this please?
if(isset($_POST['openpayslip'])){
if(!file_exists('payslips/'.$_SESSION['username'].'.pdf')){
echo "Payslip or function does not exist";
}
if(file_exists('payslips/'.$_SESSION['username'].'.pdf')){
header('Location: payslips/'.$_SESSION['username'].'.pdf');
}
}
You load the PDF file into the PHP file and then output it with a PDF header, so that people can only see one file, with some authorisation variables given.
For example, you user name is an uneditable SESSION value (in a perfect world), so you display the payslip with:
payslip.php
and in this PHP file you load
if(file_exists('payslips/'.$_SESSION['username'].'.pdf')){
$output = file_get_contents("payslips/".$_SESSION['username'].".pdf");
header("Content-type:application/pdf");
print $output;
}
This is a VERY rough and sketchy example above, but with this approach you essentially are showing the PDF file through the PHP file so the source material is never revealed directly to the end user.

download a file with php and hash

So this is simple to understand what i want to achieve. So i get links like theese:
http://rockdizfile.com/atfmzkm7236t
http://rockdizfile.com/xuj5oincoqmy
http://rockdizfile.com/pg8wg9ej3pou
So theese links are from one cloud storage site I want to make a php script that automates their downloading.
So I can't find which is the script or the thing these links download button starts and how can I start that so i can download it with php on my server?
Basically my idea is to download a lot of files but don't wanna do it manually so need automatic way of doing it. As far as I know I make a request which is the following 2 urls:
http://rockdizfile.com/pg8wg9ej3pou
http://wi32.rockdizfile.com/d/wsli6rbhfp4r2ge4t7cqeeztijrprelfiw4afvqg5iwspmvqabpkmgiz/Desislava%20feat.%20Mandi%20&%20Ustata%20-%20Pusni%20go%20pak%20(CDRIP).mp3
So the first url is executing the next one but here comes the tricky part as far as I tested that last string Desislava%20feat.%20Mandi%20&%20Ustata%20-%20Pusni%20go%20pak%20(CDRIP).mp3 is the file name we get when downloading so if you change it with for example somefile.mp3 it will download somefile.mp3 but with the same file content as http://wi32.rockdizfile.com/d/wsli6rbhfp4r2ge4t7cqeeztijrprelfiw4afvqg5iwspmvqabpkmgiz/Desislava%20feat.%20Mandi%20&%20Ustata%20-%20Pusni%20go%20pak%20(CDRIP).mp3 so the data is hidden in this hash wsli6rbhfp4r2ge4t7cqeeztijrprelfiw4afvqg5iwspmvqabpkmgiz or i think so. And now is the tricky part how to get this hash? we have almost everything we have the code for the url atfmzkm7236t the hash wsli6rbhfp4r2ge4t7cqeeztijrprelfiw4afvqg5iwspmvqabpkmgiz and the filename Desislava%20feat.%20Mandi%20&%20Ustata%20-%20Pusni%20go%20pak%20(CDRIP).mp3 There must be a way to download from this site without clicking so please help me kinda a hack this :)
you can use PHP's header function to force a file to download
header('Content-disposition: attachment; filename=index.php');
readfile('Link');
You should know that this will not give you the ability to download PHP files from external websites.
You can only use this if you got the direct link to a file
It's impossibly to tell you without the source code
e.g. sha1("Test Message") gives you 35ee8386410d41d14b3f779fc95f4695f4851682 but sha256("Vote this up") gives you 65e03c456bcc3d71dde6b28d441f5a933f6f0eaf6222e578612f2982759378ed
totally different... unless you're hidden function add's "65e03c456bcc3d71dde6b28dxxxxxxxxxxxxxxxxxxxxxxxxxx" (where xxxxxxxxxxxxxxxxxxxxxxxxxx is a bunch of numbers I can't be arsed to work out) to each hash...
then sha1("Test Message") gives you 65e03c456bcc3d71dde6b28d441f5a933f6f0eaf6222e578612f2982759378ed
The file is embedded into the swf player.
alert(jwplayer('mp3player').config.file);
Something like:
<?PHP echo file_get_contents($_GET["url"]); ?>
<script>
document.location=jwplayer('mp3player').config.file;
</script>
Though I've actually just noticed they change 5 digits of the URL on each page request, and the script above uses 2 page requests. One to get the URL and HTML source and another to try and download the file, meaning the URL has changed before the second request has started.

How to display pdf in browser

I am done with generating PDF file using FPDF in php. But the problem is how to open this pdf without the Save As option? I want to display the pdf document in the browser.
http://www.fpdf.org/en/doc/output.htm
Syntax: Output([string name] , string dest) , use I as Destination and fdpf will try to show it in the browser, if browser plugings and so on enable it
You cannot force this display, as it is up to the user to choose to display the PDF inline or systematically save them. I prefer the second option...
Now, there is a JavaScript / HTML 5 project (experimental!) to display PDF without plugin, so perhaps you can try that.
Even when using fpdf passing the output to the browser, I believe its still up to the user if they open or save it.
A solution would be to use some kind of PDF viewer, for example http://view.samurajdata.se/
Try this $pdf->Output('I', 'filename.pdf')
See the reference http://www.fpdf.org/en/doc/output.htm
Set header's content-type to 'application/pdf'. Then, most browsers will try to open it and show in-browser (or at least ask user to save or open file)
Your browser must have pdf plugin installed. If you havent done so install latest version of Acrobat Reader. If you are using fpdf, output the string instead of forcing download
For details
http://www.fpdf.org/en/doc/output.htm
Try echoing the PDF instead to using header function. The header function will force the browser to download. The echo 'might' show the pdf.

Categories