I am having Problem in saving pdf generated by mPDF to a specific folder. Every thing is working fine with pdf generation, Only I am not able to save it to a local folder. Can any one help me out with that?
Short answer is to put the full path where you plan to save the file. Like so...
$mpdf->WriteHTML($html);
$mpdf->Output('/etc/home/JohnWayne/example/pdf/','F');
I found the solution. This is very simple. As for as mPDF library is concerned, it does not parse the base_url(). Instead we have to work with $_SERVER['DOCUMENT_ROOT']; In my case i have done as; Open the config.php in Application/config folder and insert the following;
$config['file_path']=$_SERVER['DOCUMENT_ROOT']."my_project/file/";
Now it is a peace of cake to call the config; Here is I have done in the controller;
$this->mpdf->Output($this->config->item('file_path')."invoice/arif.pdf",'F');
The Problem is solved. Do let me know if there is any technical or logical issue with my code.
You can use write file helper for this
$this->load->helper('file');
write_file('my_pdf_file.pdf',$generated_pdf);
File Helper
For this follow these simple steps. Follow BASEPATH instead of APPPATH
$path = BASEPATH . 'file/invoice';
if(is_dir($path)){
$this->mpdf->Output(realpath($path).'arif.pdf','F');
}else{
echo 'error';
}
EDITS :
Here is an alternative solution which you might like
Go to application/config/constants.php and add constant there
define('FILE_PATH' , $_SERVER['DOCUMENT_ROOT']."my_project/file/");
Then use it like this.
$this->mpdf->Output(FILE_PATH ."invoice/arif.pdf",'F');
make a folder in your root directry
$mpdf->WriteHTML($html);
$mpdf->Output(FCPATH.'PDF/Broker.pdf','F');
echo $Ledger_Group_Report = base_url().'PDF/Broker.pdf';
Related
A client wants to move a website they made using Adobe Catalyst to a different hosting provider. I was able to copy the entire website via FTP and move it to the new host. Everything looks fine except for many of the links leaving code that looks like this:
{module_contentholder, name="_U309"} {module_contentholder, name="_U299"}
Does anyone know what this is or how to fix it?
Those are references to Content Holders. They work similarly to PHP's include statement, but the file they reference is fixed to a single path: /_System/ContentHolders/.
You will likely come across more tags like that, such as {module_menu} and {tag_pagecontent}. You'll need to manually adapt them to the whatever the new host uses. The documentation will help: http://docs.businesscatalyst.com/reference/
The obtuse names of the content holders shown in your example indicates the site was likely to have been generated by Adobe Muse, a WYSIWYG editor. I strongly recommend that you find the original .muse project files, and use those to update the site. Muse can compile the site for platforms other than Business Catalyst.
Through research I found out there is no way to get those codes to display properly without editing each page individually. Fortunately, I wrote a PHP script that goes through the code of each page and replaces it automatically.
Step 1: Make a file in the index directory called replacement.php
Step 2: Put this code in
$file = $_GET['file'];
$path = '/path/to/public_html/' . $file;
$file_contents = file_get_contents($path);
preg_match_all("/{module(.*?)}/", $file_contents, $matches);
foreach($matches[0] as $match) {
if(preg_match('/\"([^\"]*?)\"/', $match, $query)) {
$queryNew = str_replace("\"", "", $query[0]);
$queryPath = '/path/to/public_html/_System/ContentHolders/' . strtolower($queryNew) . '.html';
$queryContents = file_get_contents($queryPath);
$file_contents = str_replace($match, $queryContents, $file_contents);
}
}
file_put_contents($path, $file_contents);
Step 3: Replace where it says /path/to/public_html/ to your domain files location.
Step 4: go to http://www.yourdomain.com/replacement.php?file=index.html to change over the index file. You can change "index.html" in the url to any other page you want converted.
Hopefully this helps someone else in the future.
I have baked a File model and controller with default actions. Now I am trying to add an display function which can be used to show images in controlled manner.
I want to protect images so that display function can check does the user have an permissions to view image (image directory is not in a webroot).
I haven't been able to make it work, but when I started from the scratch I managed to find out that really minimal function did work.
Working function looks like this:
public function display($id) {
$this->response->file(ROOT.DS.'img'.DS.'noimage.jpg');
return $this->response;
}
When I add example:
$test=$this->File->findById($id);
to the starting of the function everything breaks.
--> http://www.example.com/files/display/1
The requested file /var/www/example.com/www/img/image.jpg was not found or not readable
Error: The requested address '/files/display/1' was not found on this server.
I have tried with debug zero, file can be found and is readable, obviously because the function without findById works.
Any ideas?
cakephp 2.4.3
You path is totally wrong.
Did you debug() what ROOT.DS.'img'.DS.'noimage.jpg' actually holds?
I bet all the money of the world that you would probably find the solution yourself if you did
The img folder is most likely in webroot
WWW_ROOT . 'img' . DS . 'noimage.jpg'
Note that paths usually end with a DS so no need to add it again.
So if it really is an image folder in ROOT:
ROOT . 'img' . DS . 'noimage.jpg'
Also note that you can easily check if a path is valid using
file_exists()
If the file has the correct file permissions this should return true.
EDIT:
$this->File->...: File is not a good choice for a model name as it collides with the existing core class in Utility. You need to be a little bit more creative with your model naming scheme.
I'm trying to make folder in controller folder with exact name like controller in Codeigniter. Is it possible by some trick or something?
Screenshot here: http://i.imgur.com/vrQ1J9V.png
If it will be like
/controllers/manage/manage.php
you should add in /config/routes.php
$route['manage/(.*)'] = "manage/manage/$1";
$route['manage'] = "manage/manage";
There is no problem in using the same name, but it is confusing. The best solution would be to change the name, but you can use just fine.
Remember to use the routes with 'manage/manage/function'.
EDIT
I incorrectly viewed the first time and thought manage.php was outside the manage folder.
It will work, but your URL will just have "manage" twice. You could change the routes config to remove the first "manage", but it will be less confusing and time-consuming to just name manage.php something different.
I have an issue in smarty cache. When an update content from admin website I am able to view the new content immediately but when i check the same page in main site i see the old content instead of new content.When i clear the templates_c dir in server and refresh the main site,I see the new content at the first attempt.I believe somewhere it has the problem with caching.Please give me a solution for this asap.Thank you.
Something like this should do (I haven't tested it myself):
<?php
$path = 'path/to/templates_c';
$dir = new DirectoryIterator($path);
foreach ($dir as $fileinfo) {
if ($fileinfo->isFile()) {
unlink($fileinfo->getPath());
}
}
?>
By the way, be very cautious when dealing with unlink(), you may accidentally delete files you didn't mean to
This question may seem a bit stupid, but i'm new to Joomla!
And i am editing a current component which i want at some point to call a small php
file that outputs data.
Now in that file i want to use joomla classes and functions for the database
like setQuery and etc.
and i want it to read the joomla prefix ( #__ ).
and the file is created by me, so i wondered what i need to include and how.
Can anyone tell me how to do that?
Thanks in advance,
Eric
It would be better not to include "external" php files, I mean files out of the Joomla structure. But if you still want to do it, you can just include that php file from anywhere you need it, and you will have all Joomla classes and functions available as long as you include that file from another Joomla tile ( maybe your component entry point, a controller, a model, view, etc.. ).
Besides, if your file outputs data, the best place to include it would be from inside a template in your component. If you use it at any other place, you should get the output for that file ( for example, with ob_start(), ob_get_contents() methods ), and save them to some kind of variable to output it from a template.
I guess you probably already know how to include that file, but if for example your file is inside a folder "mylibs" inside the joomla root, you should include it like this:
include JPATH_ROOT . DS . 'mylibs' . DS . 'myfile.php';
Why is the reason you need to include that file and it's not possible to render it as a template?
I hope it helped.
Well alghimo answer lead me into writing this :
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__));
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
/* Create the Application */
$mainframe =& JFactory::getApplication('site');
But as mentoined. not recommended on doing that.
The best way is to use an extension like Sourcer or Jumi
http://extensions.joomla.org/extensions/edition/custom-code-in-content
Good for getting started before you write 'real' Joomla installable components, modules, plugins etc...
I think the best way would be an output override. Take a look at the documentation. This way you don't have to edit a core joomla extension (of course, now that I look a little closer you don't say your editing a core extension). Anyway, output overrides are pretty cool, the use the functionality of an extension but you get to do the final modification.
In your current template folder create a folder called 'html', then take a look at the link (or another template, like beez) to determine the structure of the folder the particular extension you're overriding. Then you can call the script from within that override with all the joomla functionality, and without hacking the core.