Getting below declaration error on installing fpdf and fpdi package
Declaration of setasign\Fpdi\FpdfTplTrait::setPageFormat(array $size, string $orientation)
Try something this:
composer.json
"iio/libmergepdf": "^4.0",
"tecnickcom/tcpdf": "6.3.*",
"setasign/fpdi": "^2.0"
Using Fpdi to sign a pdf
use setasign\Fpdi\Tcpdf\Fpdi;
...
$pdf = new Fpdi('P', 'mm', 'A4');
$pages = $pdf->setSourceFile('file.pdf');
$certificate = file_get_contents('certificate.crt');
for ($i = 1; $i <= $pages; $i++) {
$pdf->AddPage();
$page = $pdf->importPage($i);
$pdf->useTemplate($page, 0, 0);
$pdf->setSignature($certificate, $certificate, 'tcpdfdemo', '', 2, array());
}
$pdf->Output($path, 'F');
Using libmergepdf to merge two pdfs
use iio\libmergepdf\Merger;
use iio\libmergepdf\Driver\TcpdiDriver;
...
$merger = new Merger(new TcpdiDriver);
$merger->addFile('file1.pdf');
$merger->addFile('file2.pdf');
$mergedPdf = $merger->merge();
return $mergedPdf;
Related
I am trying to save base64 image that is coming from the ajax post (blade file). Below is the code that I am using to save the data but it is giving 500 error.
public function add_ref_images_first(Request $request){
$fileName = "";
$end_url = "";
$count = 0;
$folder_name = 'PUBP' . time();
foreach ($request->images as $data){
$image_64 = $data['src']; //your base64 encoded data
$extension = explode('/', explode(':', substr($image_64, 0, strpos($image_64, ';')))[1])[1]; // .jpg .png .pdf
$replace = substr($image_64, 0, strpos($image_64, ',')+1);
//
// // find substring fro replace here eg: data:image/png;base64,
//
$image = str_replace($replace, '', $image_64);
$image = str_replace(' ', '+', $image);
$ref_image_id = 'PUBR'.time().$count++.'.'.$extension;
$fileName = base64_decode($image)->storeAs($folder_name, $ref_image_id , ['disk' => 'my_uploaded_files']);
if($imageName){
$end_url = $end_url.$imageName.',';
}
}
return response()->json(['url' => $end_url, 'id' => '1']);
}
Is there issue with the code?
instead of the line
$fileName = base64_decode($image)->storeAs($folder_name, $ref_image_id , ['disk'
=> 'my_uploaded_files']);
you can do :
use Illuminate\Support\Facades\Storage;
Storage::put($ref_image_id, base64_decode($image), 'local');
because basically you were trying storeAs on a string value, storeAs works on $request->file('nameFromForm')
reference: https://laravel.com/docs/8.x/filesystem
https://laravel.com/docs/8.x/filesystem#specifying-a-file-name
tried to auto download file after file created but its not working. file creating and appending data perfectly but download functionality not working
public function getexportfile(){
$this->load->dbutil();
// $this->load->database('DB_utility','dbutil');
//$this->load->helper('download_helper','download');
$this->load->helper('download_helper');
$this->load->helper('file');
error_reporting(0);
ini_set('display_errors', 0);
$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
## Condition Start
$sWhere = " where condition"; // where conditon
$date = date('Y-m-d');
$filename = 'app/logs/othermarketplace_'.$date.'.csv';
$data = $this->PMP->export($sWhere); // calling model
$result = $this->dbutil->csv_from_result($data);
write_file($filename,$result); // file creating write data perfectly
$data = file_get_contents($filename);
//$path = file_get_contents(base_url().$filename);
//$name = "othermarketplace_'.$date.'.csv";
//force_download($nme, $pth);
force_download($filename,$data);
}
anything i missed?
From docs:
// Contents of photo.jpg will be automatically read
force_download('/path/to/photo.jpg', NULL);
//$data = file_get_contents($filename);
//$path = file_get_contents(base_url().$filename);
//$name = "othermarketplace_'.$date.'.csv";
//force_download($nme, $pth);
if (!is_file($filename)) {
exit('No file found.');
}
force_download($filename, NULL);
Note:
These lines might be doing something weird. Perhaps remove them as they aren't being used:
error_reporting(0);
ini_set('display_errors', 0);
$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
Trying to reuse the following Dropbox API code within CodeIgniter. The issue is getting it to work within the constraints of class methods & constuctors:
require_once('../dropbox-sdk-1.1.4/Dropbox/autoload.php');
use \Dropbox as dbx;
$accessToken = 'DROPBOX_ACCESSTOKEN';
$dbxClient = new dbx\Client($accessToken, "PHP-Example/1.0");
Needs to be something like the following, but doesn't like the 'use \Dropbox as dbx' line, amongst others:
class Controller_name extends CI_Controller
{
public function __construct()
{
parent::__construct();
require_once('../dropbox-sdk-1.1.4/Dropbox/autoload.php');
use \Dropbox as dbx;
}
public function access_dropbox()
{
$accessToken = 'DROPBOX_ACCESSTOKEN';
$dbxClient = new dbx\Client($accessToken, "PHP-Example/1.0");
$file = 'file.txt';
$f = fopen( $file, "rb" );
$result = $dbxClient->uploadFile( "/$file", dbx\WriteMode::add(), $f);
fclose($f);
}
}
Using the code below I'm getting the following error message:
An uncaught Exception was encountered
Type: Kunnu\Dropbox\Exceptions\DropboxClientException
Message: Error in call to API function "files/upload": HTTP header
"Dropbox-API-Arg": path: 'db_backup' did not match pattern
'(/(.|[\r\n]))|(ns:[0-9]+(/.)?)|(id:.*)'
Filename:
/opt/lampp/htdocs/codeig-smythes/vendor/kunalvarma05/dropbox-php-sdk/src/Dropbox/Http/Clients/DropboxGuzzleHttpClient.php
Line Number: 59
$file_path = 'public/sql_backup/db_backup_' .date("Y-m-d"). '.sql';
require_once('../vendor/autoload.php');
$app = new Kunnu\Dropbox\DropboxApp(
'APP_KEY',
'APP_SECRET',
'ACCESS_TOKEN'
);
$dropbox = new Kunnu\Dropbox\Dropbox($app);
$dropboxFile = new Kunnu\Dropbox\DropboxFile(realpath($file_path));
$file = $dropbox->upload(
$dropboxFile, basename($file_path), array('autorename' => TRUE)
);
Working with the dropbox API is pretty easy. I use a package found on github:
https://github.com/kunalvarma05/dropbox-php-sdk
I am not using CodeIgniter 3's composer autoload feature. Also, my vendor directory is located at FCPATH.
Since it looks like you want to upload a file, I'll show you that example:
$appKey = '77fgftsb77joj77';
$appSecret = 'fw77777tspam5y';
$accessToken = 'PMP7777777AAAAAAADFC_6JI7777777hY8xYhO7777777MJkpCKbBv';
if( is_file( $file_path ) )
{
$file_path = realpath( $file_path );
$file_name = basename( $file_path );
require FCPATH . 'vendor/autoload.php';
$app = new Kunnu\Dropbox\DropboxApp(
$appKey,
$appSecret,
$accessToken
);
$dropbox = new Kunnu\Dropbox\Dropbox($app);
$dropboxFile = new Kunnu\Dropbox\DropboxFile(
$file_path
);
$file = $dropbox->upload(
$dropboxFile,
'/backups/website/' . $file_name,
[
'autorename' => TRUE
]
);
}
I'm using intervention/image for laravel and upload laravel project in my Host but image not upload.
However, PHP Fileinfo in my host in enable and use php version 5.4 .
error text :
"error":{"type":"LogicException","message":"Unable to guess the mime type as no
guessers are available (Did you enable the php_fileinfo
extension?)","file":"\/home\/investi1\/vendor\/symfony\/http-
foundation\/Symfony\/Component\/HttpFoundation\/File\/MimeType\/MimeTypeGuesser.
php","line":127}
Controller :
$image = Input::file('file');
$destinationPath = 'uploads/gallery';
$filename = $image->getClientOriginalName();
$extension =$image->getClientOriginalExtension();
$image_filename = sha1($filename).'-'.rand(0,1000).'.'.$extension;
$image_uploadSuccess = $image->move($destinationPath, $image_filename);
$img = Image::make($destinationPath.'/'.$image_filename);
$img->resize(150, null, function ($constraint) {
$constraint->aspectRatio();
})->save($destinationPath.'/tumb/'.$image_filename,70);
$img_gallery = new ImageGallery;
$img_gallery->user_id = Sentry::getUser()->id;
$img_gallery->lang = Security::xss_clean(Input::get('lang'));
$img_gallery->description = Security::xss_clean(Input::get('description'));
$img_gallery->cat_id = Security::xss_clean(Input::get('category'));
$img_gallery->image = $image_filename;
$img_gallery->created_at = jDate::forge()->time();
if( $image_uploadSuccess ) {
$img_gallery->save();
return Response::json('success', 200);
} else {
return Response::json('error', 400);
}
enable PHP extension php_fileinfo, to do this find your php.ini file and uncomment following line
; windows
extension=php_fileinfo.dll
OR
; linux
extension=php_fileinfo.so
I write custom module, for example, when module called with parametr 1, module return 1, when called with 2, return 2 e.t.c.
But I cant find any documentation, how to send parametrs from page to module. Its how I call module now:
jimport( 'joomla.application.module.helper' );
$modules = JModuleHelper::getModules('NAME_OF_CUSTOM_POSITION');
$count_array = count($modules);
if ($count_array >0)
{
$attribs['style'] = 'xhtml';
echo JModuleHelper::renderModule( $modules[0], $attribs );
}
?>
But I don't know how to send params nor how to recieve them in my module.
I have used below code in one of my custom component.And it worked for me.
$document = JFactory::getDocument();
$renderer = $document->loadRenderer('module');
$params = array('style'=>'xhtml');
$contents = '';
foreach (JModuleHelper::getModules('NAME_OF_CUSTOM_POSITION') as $mod) {
$registry = new JRegistry();
$registry->loadString($mod->params);
$registry->set('paramname','paramvalue');
$mod->params = (string)$registry;
$contents .= $renderer->render($mod, $params);
}
echo $contents;