Codeigniter pdf file password not working Google Drive - codeigniter

I am creating codeigniter pdf file download with password, using mpdf library. pdf file upload and view using password not working google drive. how to resolve, help me.
Library
<?php
if(!defined('BASEPATH'))exit('No direct script access allowed');
class m_pdf {
#code
function m_pdf(){
$CI = & get_instance();
log_message('Debug', 'mPDF class is loaded');
}
function load($param=NULL){
include_once APPPATH.'/third_party/mpdf/mpdf.php';
if($params == NULL){
$param = '"en-GB-x", "A4", "", "", 10,10,10,10,6,3';
}
return new mPDF($param);
}
}
Controller
class Welcome extends CI_Controller {
public function __construct(){
parent::__construct();
}
public function index()
{
$this->load->library('m_pdf');
$pdf = $this->m_pdf->load();
$data = [];
$passWord = 'test123';
//password generate PDF
$pdf->SetProtection(array(), $passWord);
//$data['the_content']='mPDF and CodeIgniter are cool!';
$html = $this->load->view('welcome_message', $data, true);
$pdfFilePath = 'pdf_output.pdf';
$pdf->WriteHTML($html);
//print_r($pdf);
$pdf->Output($pdfFilePath, "D");
return $pdfFilePath;
}
}

This is a known bug in mPDF - see respective mPDF Github issues
FYI: Gmail In-Browser Document Viewer won't open Encrypted PDFs generated with mPDF #171
PDF opening without password when using Finder on Mac #181
You can:
either password-protect the file using an external tool,
use en external tool entirely (TCPDF handles encryption correctly),
or wait until the issue is resolved in mPDF which can take a substantial time.

Related

how to save pdf inside controller and pass pdf patch

pdf api -> https://github.com/barryvdh/laravel-dompdf
I create some simple API, everyone who pass some data will recaive link to pdf file.
The thing is, i dont know how to save pdf after conroller make changes inside my blade template.
so...
i already try changing data by request and that was working.
something like :
class pdfGenerator extends Controller
{
public function show(Request $request)
{
$data = $request->json()->all();
return view('test2', compact('data'));
}
}
that work well, also pdf creator works well from web.php
Route::get('/test', function () {
$pdf = PDF::loadView('test2');
return $pdf->download('test2.pdf');
});
that one just download my pdf file as expected.
but, now i try to pust some changes from request and save file but... without efford... any idea?
My code after tray to save content
class pdfGenerator extends Controller
{
public function show(Request $request)
{
$data = $request->json()->all();
return $pdf = PDF::loadView('test2', compact('data'))->save('/pdf_saved/my_test_file.pdf');
}
}
But i get only some errors. Please help :D
How can I save a PDF inside my controller and pass the PDF patch?
$data = $request->json()->all();
$pdf = app('dompdf.wrapper');
$pdf->loadView('test2', $data);
return $pdf->download('test2.pdf');

Dynamic social app credentials in socialite package in Laravel

I'm trying to build a multi tenant app, where I have configured the database, the views folder, I know there must be some way out to configure the credentials of social app login for socialite. Well I tried few things to set it dynamically.
STEP 1
I created a class with the name of socialite in a separate folder and when the social login is called I'm implementing the following in my controller:
public function redirectSocialLogin()
{
$social = new SocialiteProvider();
$fb = $social->makeFacebookDriver();
return $fb->redirect();
}
and while callback I used following:
public function callbackSocialLogin($media)
{
$user = Socialite::driver($media)->user();
$data['name'] = $user->getName();
$data['email'] = $user->getEmail();
dd($data);
}
In my class I've following codes:
public function makeFacebookDriver()
{
$config['client_id'] = 'XXXXXXXXXXXXXXX';
$config['client_secret'] = 'XXXXXXXXXXXXXXX';
$config['redirect'] = 'http://XXXXXXXXXXXX/auth/facebook/callback';
return Socialite::buildProvider('\Laravel\Socialite\Two\FacebookProvider', $config);
}
It redirects perfectly to the social page but while getting a callback I'm getting an error, It again fetches the services.php file for configuration and doesn't get any.
STEP 2
I made a ServiceProvider under the name of SocialiteServiceProvider and extended the core SocialiteServiceProvider and placed the following codes:
protected function createFacebookDriver()
{
$config['client_id'] = 'XXXXXXXXXXXXXXX';
$config['client_secret'] = 'XXXXXXXXXXXXXXXXXXXX';
$config['redirect'] = 'http://XXXXXXXXXXX/auth/facebook/callback';
return $this->buildProvider(
'Laravel\Socialite\Two\FacebookProvider', $config
);
}
But again it throws back error which says driver is not setup. Help me out in this.
Thanks.
In your STEP 1, update the callback as below mentioned & try. $media is actually Request. So when initialising Socialite::driver($media) you are actually passing Request where you have to pass Facebook.
public function callbackSocialLogin(Request $request) {
$fbDriver = (new SocialiteProvider())->makeFacebookDriver();
$user = $fbDriver->user();
$data['name'] = $user->getName();
$data['email'] = $user->getEmail();
...
}

codeigniter ftp get filesize

How can i get remote file's file size with codeigniter?
after making a connection , i want to get properties.xml file's size. in ordinery ftp i would get it with no problem but since i start using codeigniter it is kinda difficult.
this is in procedurel php ;
$remote_filesize = ftp_size($conn_id, "properties.xml");
but how can i do it in codeigniter?
if($this->ftp->connect($config))
{
/*here some magic code*/
}
this a small example
Controller_ftp.php
class Controller_ftp extends CI_Controller{
public function __construct(){
parent::__construct();
$this->load->library('ftp');
}
publilc function get_ftp_info(){
$config['hostname'] = 'ftp.example.com';
$config['username'] = 'your-username';
$config['password'] = 'your-password';
$config['debug'] = TRUE;
foreach($this->ftp->list_files('/public_html/') as $item){
$size = filesize($item);
echo "name => $item - size => $size - etc <br>";
clearstatcache();
}
}
}
If you want to use $this->ftp->file_size($file), you need to extend ftp library and create the function retunring filesize($item);
ok i went to library->ftp.php and basically added a function
public function get_conn_id()
{ return $this->conn_id;}
and later all i need to do was calling the function like this
$conn_id = $this->ftp->get_conn_id();
$remote_filesize = ftp_size($conn_id, "properties.xml");

Codeigniter extend Blueimp Upload library

I have blueimp file upload working well with codeigniter. I use the UploadHandler library as is. But I want to extend it to replace two functions that create the unique filename. The code for this is in the BlueImp Github wiki.
I created an extended library thus:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_UploadHandler extends UploadHandler {
public function __construct() {
parent::__construct();
$CI =& get_instance();
$CI->load->library('UploadHandler');
}
protected function upcount_name_callback($matches) {
$index = isset($matches[1]) ? intval($matches[1]) + 1 : 1;
$ext = isset($matches[2]) ? $matches[2] : '';
return '-'.$index.''.$ext;
}
protected function upcount_name($name) {
return preg_replace_callback(
'/(?:(?:-([\d]+))?(\.[^.]+))?$/',
array($this, 'upcount_name_callback'),
$name,
1
);
}
}
When I try to run it, I get an 'unable to load UploadHandler' error. If I remove my MY extension, the original code runs. What is wrong with my extension code? Isn't this the proper way to extend CI libraries?
And, yes, the filename for my file is MY_UploadHandler.php
Thanks!
I noodled over this for a while and finally figured it out. To extend a custom library, you need to 'require once' the file it is extending, prior to the definition of the class.
EX:
require_once("UploadHandler.php");
class MY_UploadHandler extends UploadHandler
{
}
Hopefully that helps.

Rolling-curl Codeigniter library

I've been using this rolling-curl library with success outside of Codeigniter http://code.google.com/p/rolling-curl/source/browse/#svn%2Ftrunk
I want to use the library with Codeigniter but cannot get it to work.
I've created a file called Rollingcurl.php and placed in codeigniter's application/library folder. In this file I've copied the originals RollingCurl.php file's content (see RollingCurl.php file in link posted above).
My controller looks like this:
class Rolling_curl extends CI_Controller {
function __construct()
{
parent::__construct();
}
function index(){
$this->load->library('rollingcurl', 'request_callback');
$this->rollingcurl->request("http://www.google.com");
$this->rollingcurl->execute();
}
function request_callback($response, $info, $request) {
// parse the page title out of the returned HTML
if (preg_match("~<title>(.*?)</title>~i", $response, $out)) {
$title = $out[1];
}
echo "<b>$title</b><br />";
print_r($info);
print_r($request);
echo "<hr>";
}
In the index function I'm loading the rollingcurl library I've created from the orginal RollingCurl.php and passing the parameter 'request_callback', which is the name of the other function in the controller (see orginal rolling-curl example: http://code.google.com/p/rolling-curl/source/browse/trunk/example.php).
But, it doesn't work... What am I doing wrong?

Resources