how to download office 365 mail attachment file using laravel/PHP - laravel-5

I'm using Microsoft graph API for fetching office 365 mails. I got all the emails from the API call but I don't know how to save an attachment from the message object. How do I save contentBytes to file?
Microsoft\Graph\Model\Message Object
(
[_propDict:protected] => Array
(
[#odata.context] => https://graph.microsoft.com/v1.0/$metada
[#odata.type] => #microsoft.graph.fileAttachment
[#odata.mediaContentType] => application/pdf
[id] => AAMkADM4MDYwMDkxLWRmN2UtNDJmMC04NDEwLTljZmQ2N2I4Zjc5NABGAAAAAAAix7kDZj2fRq
[lastModifiedDateTime] => 2016-04-18T09:44:53Z
[name] => 1 ) Muhammad Abdullah New.pdf
[contentType] => application/pdf
[size] => 104767
isInline] =>
[contentId] => C#$F3#eurprd06.prod.outlook.com
[contentLocation] =>
[contentBytes] => JVBERi0xLjUNJeLjz9MNyuFJFtfTffYSTIgCjUwNSAwIG9iag08PC9MaW
)
)

Finally i got a solution.We get base64_encoded contentBytes from the Graph API, we need to convert contentBytes to base64_decode format.so you have to write base64_decoded content to a file.
$content=base64_decode($attachment_data->getcontentBytes(),true);
file_put_contents(public_path(). "/sample/".$attachment_data->getname(),$content);
// download code

Related

Oracle APEX print with API

I need to export a report saving it in PDF format. I created a button that submits to a new page, which performs the following piece of code:
APEX_UTIL.DOWNLOAD_PRINT_DOCUMENT (
p_file_name => 'myreport123',
p_content_disposition => 'attachment',
p_application_id => :APP_ID,
p_report_query_name => 'MY_REPORT_QUERY',
p_report_layout_name => 'MY_REPORT_LAYOUT',
p_report_layout_type => 'xsl-fo',
p_document_format => 'pdf'
)
;
MY_REPORT_QUERY and MY_REPORT_LAYOUT are defined in the shared components. When I press the button, it downloads a pdf file, but it looks empty or corrupted.
What could be wrong? Do I need to specify the print server? And what about the field APP_ID?
I can confirm that both the query and layout work when I download the report by directly redirecting the page to the url of MY_REPORT_QUERY.
Thanks in advance and best regards.

OS Ticket Open Ticket CSRF Token Dump Error

When i open new ticket in OS Ticket System, after ticket submission dump the array in the top of the page.
Error shown below.
Click to show image
Update
Error in text form:
Array ( [CSRFToken] => a56c08a9f49842de2ab3fc8e02d13ca2921d5f49 [a] => open [695fbbb799cdbbc2] => usman.saif22#gmail.com [ecf6c52d42557ef0] => M Usman [fec356fce5ea2de9] => [fec356fce5ea2de9-ext] => [topicId] => 2 [83163d48527225db] => Testing [message] => Testing [draft_id] => [emailId] => 0 [deptId] => 0 [cannedattachments] => Array ( ) )
This error occur when open new ticket, even ticket is successfully opened. But, shown this error when user open ticket.

Zip multiple files and download using php codeigniter

I am trying to create a zip file including 2 text files and download it. Here is my code. $fda and $fwl are 2 array datas.
$dataZip = array(
'./downloads/fda.in' => $data1,
'./downloads/fwl.in' => $data2
);
$this->zip->add_data($dataZip);
$this->zip->archive('./downloads/files_backup.zip');
$this->zip->download('files_backup.zip');
But it always returns error as a wrongly formatted string and nothing is downloaded.
fda.in�X�n�0}�+�
Could anybody tell me where I was wrong?
I found out the solution. All I have to do is add ob_start(); in the open of the controller file.
ob_start();
$dataZip = array(
'./downloads/fda.in' => $fda,
'./downloads/fwl.in' => $fwl
);
$this->zip->add_data($dataZip);
$this->zip->archive('./downloads/files_backup.zip');
$this->zip->download('files_backup.zip');

How to save a backup of mails sent through MIME::Lite in Perl 5?

I am sending mail through MIME::Lite perl module.I want that my sent mails should be saved in Sent items folder of my mail inbox.Please suggest me a way to do this.
Thanks
script-
use MIME::Lite;
my $msg = MIME::Lite->new(
From => 'xyz#abc.com',
To => 'abcd#gmail.com',
Subject => 'sending mail',
Type => 'multipart/mixed',
);
$msg->attach(
Type => 'TEXT',
Path => '/home/user/myName/cppLab/a.txt',
Filename => 'aabc.txt',
Disposition => 'attachment',
);
$msg->attach(
Type => 'TEXT',
Data => "learning to send mail",
);
#$msg->print(\*STDOUT);
#$msg->print_header(\*STDOUT);
$msg->send;
print "mail sent.."
Depends on how you access your inbox. In any case, you'll probably need MIME::Lite's as_string method that you can call on messages to retrieve the entire text including headers and possibly attachments.
For local mailboxes:
If your mail folders use the Maildir format, you could use Maildir::Lite to simply write the returned string to an appropriately named (Maildir::Lite does that for you) file.
For mbox folders, have a look at Mail::Box::Mbox
Local mailboxes can be handled in just a few lines of Perl. If your inbox is remote and needs IMAP, there's always IMAP::Client but I don't really have a clue about it. Perhaps a local Maildir plus offlineimap would do, too?

How to translate upload errors on CodeIgniter

I am using CodeIgniter to upload some files through a form. I know how to translate "regular" form errors (required, valid_email, etc) but I don't know how to do it with file errors (file is not allowed, file is too big, etc).
Which keys should I use in
$this->form_validation->set_message('KEY', 'TRANSLATION');
?
Thanks
METHOD 1
By default, language files are typically stored in system/language directory. Alternately you can create a file called upload_lang.php inside your application/language folder and store them there.
$lang['upload_userfile_not_set'] = "Unable to find a post variable called userfile.";
$lang['upload_file_exceeds_limit'] = "The uploaded file exceeds the maximum allowed size in your PHP configuration file.";
$lang['upload_file_exceeds_form_limit'] = "The uploaded file exceeds the maximum size allowed by the submission form.";
$lang['upload_file_partial'] = "The file was only partially uploaded.";
$lang['upload_no_temp_directory'] = "The temporary folder is missing.";
$lang['upload_unable_to_write_file'] = "The file could not be written to disk.";
$lang['upload_stopped_by_extension'] = "The file upload was stopped by extension.";
$lang['upload_no_file_selected'] = "You did not select a file to upload.";
$lang['upload_invalid_filetype'] = "The filetype you are attempting to upload is not allowed.";
$lang['upload_invalid_filesize'] = "The file you are attempting to upload is larger than the permitted size.";
$lang['upload_invalid_dimensions'] = "The image you are attempting to upload exceedes the maximum height or width.";
$lang['upload_destination_error'] = "A problem was encountered while attempting to move the uploaded file to the final destination.";
$lang['upload_no_filepath'] = "The upload path does not appear to be valid.";
$lang['upload_no_file_types'] = "You have not specified any allowed file types.";
$lang['upload_bad_filename'] = "The file name you submitted already exists on the server.";
$lang['upload_not_writable'] = "The upload destination folder does not appear to be writable.";
METHOD 2
You can use Flashdata after upload process.
if ($this->upload->do_upload())
{
$this->session->set_flashdata('success', 'Yep! Upload complete');
redirect('go_back_home');
}
else
{
$this->session->set_flashdata('error', 'Uh, upload not complete! The problem is..'); // Manually check
redirect('go_back_form');
}
You can also check the problem with $this->upload->data(). This is a helper function that returns an array containing all of the data related to the file you uploaded. Here is the array prototype :
Array
(
[file_name] => mypic.jpg
[file_type] => image/jpeg
[file_path] => /path/to/your/upload/
[full_path] => /path/to/your/upload/jpg.jpg
[raw_name] => mypic
[orig_name] => mypic.jpg
[client_name] => mypic.jpg
[file_ext] => .jpg
[file_size] => 22.2
[is_image] => 1
[image_width] => 800
[image_height] => 600
[image_type] => jpeg
[image_size_str] => width="800" height="200"
)
Try this:
lang:your_translation_key
A real example:
$this->form_validation->set_rules('name', 'lang:web_name', 'required|trim|xss_clean|min_length[2]|max_length[100]');

Resources