Export data to XML with sepa-xml-php - php

please I need help I'm trying to create a SEPA XML file so I downloaded the sepa-xml with coenter image description heremposer in my project then I make the same code in the documentation to test if work or not so when I enter image description hereadded the code and generate the file I get an empty file. but when I dump the variable I get a result .
I get this page

I referred here. Looks like you need to download the generated xml code.
[Git link][1].
Code will be like this.
header('Content-disposition: attachment; filename="newfile.xml"');
header('Content-type: "text/xml"; charset="utf8"');
echo $directDebit->asXML();
exit;
In this case the generated code will be saved as newfile.xml and download the file automatically. Hope it solves your problem
[1]: https://github.com/php-sepa-xml/php-sepa-xml/blob/master/doc/direct_debit.md

Related

How to save as xls from mysql fetching data to www/data/ folder using php?

I am new to PHP development. I am creating excel.xls using the mentioned header information, whereas it is saving as xls at default download folder. Actually, when I click export link, this test.xls file should be saved to www/data/ folder instead of downloading it.
How can I give path for new location to save file using PHP dynamically?
code as follows:
$file = "test.xls";
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment;Filename=$file");
code end
Please help if possible.
Thanks in advance.
Best regards,
Balraj
You can use file_put_contents in PHP.
$file = "path/test.xls";
$data = "Keep your data into this variable";
file_put_contents($file,$data);
file_put_contents is wrapper for fopen,fwrite,fclose.For more information check here

Using php to force download a pdf

Im trying to get a website to have a button that forces a download of a pdf.
Heres the html of the button:
<a href=scripts/download.php>
<input type="image" src="images/download.gif" alt="Submit button"/>
</a>
And the php script so far:
<?php
header('Content-Type: application/pdf');
header('Content-disposition: attachment;filename=documents/ECM_IT_ResumeDownload.pdf');
readfile('documents/ECM_IT_ResumeDownload.pdf');
?>
This seems to download the file fine but when I go to open it i get this error:
"Adobe Reader could not open 'documents_ECM_IT_ResumeDownload.pdf' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded)."
Any help would be greatly appreciated.
EDIT
Opened the pdf in a text editor and got this message:
"
Warning: readfile(documents/ECM_IT_ResumeDownload.pdf) [function.readfile]: failed to open stream: No such file or directory in html/scripts/download.php on line 4
"
The document is definitely there though. in html/documents/ECM_IT_ResumeDownload.pdf
$file_url = www.example.com/pdffolder/$pdfname;
header('Content-Type: application/pdf');
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=".$pdfname);
readfile($file_url);
Try removing the path to the file and just leave the file name in the content:
header('Content-Type: application/pdf');
header('Content-disposition: attachment; filename=ECM_IT_ResumeDownload.pdf');
Have you tried getting rid of the closing PHP tag (the ?>) at the end? It will treat the page as a pure PHP page, removing any possible new lines that might accidentally get appended to the end of the output. This helped me when I was dynamically creating excel files for download, and they were downloading as corrupted. Check out this page for more information:
http://www.php.net/manual/en/language.basic-syntax.phptags.php
From your edited question, it seems like PHP is unable to find the file. Try using an absolute path to the file like so: "c:\blah\de\blah\bloo.pdf" or "c:/blah/de/blah/bloo.pdf". If one of those paths works and downloads correctly, your relative path is incorrect in some way.
I always use Gowon Patterson's download script, it also has hotlink protection:
http://by.gowondesigns.com/getfile/
By the way, a bit late, but to identify the problem properly here:
Your download script is at scripts/download.php and the file you want to download is at documents/[...].pdf.
Therefore, your readfile() function should be traversing to the parent directory (outside of scripts/), e.g. readfile('../documents/[...].pdf');.

Storing / Extracting images from database with php

I am using PHP 5.3.5 and postgreSQL. I am storing and extracting images from database.
For storing i am doing this:
$escaped_data = base64_encode(file_get_contents($_FILES['fileUpload']['tmp_name']));
$fileModel->setBinary_Data($escaped_data);
It's working, i received the image in my database (Bytea field).
The problem is to extract this, i am trying this code to extract my images:
$file_info = $fileModel->getBinary_Data($id_file); // This function return the binary_data of the image
header('Content-Type: image/jpeg;base64');
header('Content-Disposition: attachment; filename=' . $file_info['_name']);
base64_decode($file_info['binary_data']));
When i download the image, i can't see the image...
With echo in:
echo base64_decode($file_info['binary_data']);
This happen:
http://imageshack.us/f/18/encodez.jpg/
After, i am trying using the function stream_get_contents inside base64_decode, but doens't work.
Someone know how i can download my images with php?
Thanks anyway...
Well obviously your custom getBinary_Data() returns $file_info['binary_data'] as a resource, not a string.. so either change the function or use base64_decode(file_get_contents($file_info['binary_data'])));
And try to use fclose($file_info['binary_data']); too then.
P.S. Wasn't there a blob type for binary data in postgre?

Create Download link using PHP from the database

i wanna ask again,still have problems with my php code
i wanna ask how to create download link that looping from database, the file store in localhost in folder attach,anyone can help
my php code to show the attachment file store in database like this
<?php
if ($row['filename']==NULL)
{echo "no attachment"; }
else
{echo $row['filename']; }
?>
from that generated i want to create a download link which is stored in my localhost
my attachment like it contains only 2 columns file name and file size
Regards
Wahyu
Can you please explain your question more? Im not able to comment on questions yet, so I have to add an answer.
A general answer is:
In your database your store the filename of the file you want to be downloaded. Next, you generate a link with php and use the filename of the database.
After your edit/comment, something like this:
<?php
if ($row['filename']==NULL){
print "no attachment";
}else{
printf("<a href='yourhost.com/folder/%s'",$row['filename']);
}
?>
For making download link, you need to set appropriate headers.
For example
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename='.$filename);
To solve your problem, you can have a link like http://site.com/downloads.php?id=12456.
In the downloads.php page. you can check for the file name . and set the header in that page. Also its not necessary to have the content-type header.

Php Download script isn't working

I have a script which uploads files into an online directory and stores the file details in a database. The files when stored are renamed to the id of the entry in the database. Whenever a user requests a download, a simple SQL statement retrieves the file details from the database, the contents of the file are read from the database, and the file is prompted for download. The following is my code:
$one_file = $FILE_OBJECT->get($_GET['id']); // this is an object which just grabs the file details from the database
header("Content-type: ".$one_file['type']); // add here more headers for diff. extensions
header("Content-Disposition: attachment; filename=\"".$one_file["filename"]."\""); // use 'attachment' to force a download
header("Content-type: application/octet-stream");
header("Content-Disposition: filename=\"".$one_file["filename"]."\"");
readfile(_config('files_path').$_GET['id']);// reading the actual raw file stored in my online directory
Problem is that Im testing using a word document and its uploading perfectly - I've even checked the raw file being uploaded by manually changing its extension and it's uploading perfectly. The problem is that when it's downloaded using the code above, the Word file seems corrupted or something, because when I try to open it, it's all mumbled and jumbled. What's happening? I've used this snippet on a few other sites I've worked on, and they work perfectly fine... Help please!
By default PHP's header function will replace previous headers with the same name, so your first two headers are being overwritten by the second two. Delete the second two and see if that works.
See if this helps:
Webkit and Excel file(PHPexcel)
I was having the same problem: every time I downloaded a file, it was supposedly "corrupt". Turns out I had made a stupid directory path mistake, but the php error was being written into the downloaded file. Which, of course, made it "corrupt".
Actually I solved by reading Ian Wetherbee's comment about testing with a plain text file. Thanks Ian!

Categories