FDF file doesn't work with URL - php

I am using a PHP script to generate FDF response and in that response the PDF template is supplied as a remote file "https://platweb-eur.qa.reachlocal.com/test/546_df50ab50418e1e925e81020815217649.pdf"
This is opening up the PDF template properly, but the fields are not getting populated.
While I am using local PDF template instead of file URL for the same pdf, fields's value were getting populated correctly.
So the issue is with remote file. Can anybody point me to what is going wrong here ?

Related

Laravel storage::download(path_to_file) not working as required with .doc/.docx

I am trying to Storage::download(file_path) but with pdf file type it showing pdf file in postman, however with .doc/.docx it is returning some garbage value. I want to return doc file like pdf, below is attached pdf and doc postman response:

PHP: save a file (generated by aspx) to server

I have an url provided by a wholesaler. Url generates xml file which I need to save on my server.
I use PHP - file_get_contents and file_put_contents to do that:
$savepath = "path_to_my_server_folder";
$xmlurl = "http://usistema.eurodigital.lt/newxml/xmlfile.aspx?xml=labas&code=052048048048051057049050048049052";
file_put_contents($savepath.'eurodigital.xml', file_get_contents($xmlurl));
File is generated on my server, but its content is empty. I have no problems with other xml files if I provide direct xml url, but in this situation file is generated by aspx file dynamically. Xml url is actual url I use. When I open xmlurl in browser, xml file gets saved to device.
Can you help me with moving xml to my server? What function should I use? Is it even possible to do that using PHP 5? "allow_url_fopen" is ON.
Thank you in advance!

loading document with error when open with pdf js

I have a strange question regarding PDF.JS and PHP
Using PDF.JS, to open pdf you should use on browser:
http:// ...url... /viewer.html?file=[filename]
I have changed viewer.html extension to viewer.php and developed an additional file document.php to get data from database and load a local PDF file, and I use in this way to get PDF
... viewer.php?file=document.php&control=5E71581C52B96
All work great , AS ESPECTED, but i'm experiencing trouble when get variables from database.
When I Use fileurl like this, PDF load correctly:
$fileurl = 'D:\Drive\_DEV\storage\220\2020-03-17\00000000002\1584486427900.pdf';
When I use fileurl like this (variables from database) PDF not open and have error
Corrupted or inválid PDF Invalid PDF structure
$fileurl = $storage_path.'\\'.$storage_folder.'\\'.$document;
If I echo, $fileurl in both cases i have exactly same result.
Regarding SQL QUERY below, on WHERE Clause if I change '$doc_control' (from request) with '5E71581C52B96' (instead '$doc_control') PDF load correctly into pdf.js
If I echo $doc_control, number is exactly same, only difference is how put value on WHERE (number or variable)
If i open document.php work with no problems.
What do I Wrong? Any help is very appreciated.
DOCUMENT.PHP
// REQUEST
$doc_control = $_REQUEST['control'];
// Read database
SELECT *
FROM docs
WHERE doc_control = '$doc_control'
// FILE PATH
$fileurl = $storage_path.'\\'.$storage_folder.'\\'.$document;
// READ PDF
header("Content-type:application/pdf");
header("Content-Disposition:inline;filename=".$fileurl);
//#readfile($fileurl);
$file=fopen($fileurl, "r") or die('Unable to open file');
echo fread($file,filesize($fileurl));
fclose($file);

Chrome opening CSV file instead of save it

I have a PHP application that generates a CSV file and redirect the user to a static page linking to the file, just the example below :
https://www.example.com/public_html/static/temp/myfile.csv
Problem is, Chrome is opening the file instead of saving it. I need Chrome to save this file, as it would do with any other file like a zip or mp3, for instance.
Here is what I tried :
header('location:https://www.example.com/public_html/static/temp/myfile.csv');
header('Content-Disposition: attachment; filename=myfile.csv');
But no luck, Chrome keeps showing the myfile.csv contents instead of downloading it.
Any ideas ?
Thanks
Your argumentation in the comments has one never-ending misunderstanding: the Location header instructs any client to perform a new request to the given URI. With that the current request is over. Headers from the current request (i.e. Content-Disposition) aren't magically carried over to the next request.
In other words: your "static page linking to the file, just the example below" must send your wanted header.
Ultimately I'm sure it's not a Chrome problem either, but affects all internet browsers, as they easily detect the CSV data as text, hence being able to render/display that data instead of only being able to save it to a file.
With html5 you can set the "download" attr in an element.
Download it!
Source : http://updates.html5rocks.com/2011/08/Downloading-resources-in-HTML5-a-download
After struggling with this issue for some days, the only real solution i got is to ZIP the file and then redirecting to the ZIP file instead of the CSV. By doing this, Chrome will download the ZIP file instead of opening it :
header('location:https://www.example.com/public_html/static/temp/myfile.csv.zip');

Preview pdf file created with TCPDF in embed tag after Ajax call

So my application generates pdf files using TCPDF, and that works fine. That is done inside php file, called with ajax. I'm using embed tag to preview them like:
$.ajax({
url: 'create_pdf_file.php',
success: function(){
/* https://stackoverflow.com/questions/17083018/jquery-loads-cached-file-inside-ajax-success-function */
$('#pdf_placeholder embed').attr('src','output/my_file.pdf?v=' + Math.random()');
}
});
Because many users could generate my_file.pdf at the same time, there could be a case when one user will preview a file generated for another user. So my question at this point is how to force TCPDF to output directly into that tag, not using temp file
Output('my_file','I')
not working here after ajax.
There is an advice here to echo pdf directly back, but i don't know how to do that or is it possible at all. Anyway will try with success(data) to receive that like json.
Other workaround is to give session-bond file name for each user, but is using session_id() and appending to the file name is safe? Most probably I will end with generating UID for each session.
Any general advices are welcome.
You should try passing what TCPDF will produce in a way widely used in embeding images: Data Uri
Embedding Base64 Images
This however might choke browser - i haven't test this.
I would rather save pdf file on server, print filename to browser or other ID of produced file so it could be read with "success" of the ajax request. Then calmly pass proper filename to Embed element. If you wish to do it more safely you can encode it using already used session-exclusive data like session cookie or data that is assosiated with that cookie on a server. You can bond pdf file access to IP that sent request to produce it and timestamp of request that caused production.

Categories