MeioUpload isn't creating thumbnails in cakephp 2.4 - cakephp

I'm using meioupload and everything works well till I try to make thumbnails. Then I can see only kind of phpThumb error message which says
"C:/wamp/cakephp/vendors/phpTmub/img/uploads/product/filename/image.png" does not exist
I'm new with cakePHP so I never faced this problem before. Does anyone know what should I do?
here is my model code:
var $actsAs = array(
'MeioUpload' => array(
'filename' => array(
'create_directory' => true,
'allowed_mime' => array('image/jpeg', 'image/pjpeg', 'image/png'),
'allowed_ext' => array('.jpg', '.jpeg', '.png'),
'zoomCrop' => true,
'thumbsizes' => array(
'normal' => array('width' => 400, 'height' => 300),
'small' => array('width' => 80, 'height' => 80,'maxDimension' => '', 'thumbnailQuality' => 100, 'zoomCrop' => true),
),
'default' => 'default.jpg'
)
));
UPDATE:
I found special phpThumb for cakePHP 2.0 so the Path changed into this:
"C:/wamp/cakephp/img/uploads/product/filename/image.png"
and if I open default image in my browser th path is like:
localhost:8080/cakephp/img/uploads/product/filename/image.png
Thanks

I solved the problem, maybe not very elegant, but it works!
For the first time, as I said, I downloaded special version of phpThumb for cakePHP.
Here is link: https://github.com/simkimsia/phpThumb-for-cakephp-2.0
After there was my problem with the path because my images was in folder: C:\wamp\www\cakephp\app\webroot\img\uploads\product\filename\image.png
So I had to find this part of code(begins on line 1078):
if ($this->useCake) {
if ($this->config_document_root != null) {
$AbsoluteFilename = $this->config_document_root.DIRECTORY_SEPARATOR.$filename;
} else {
$AbsoluteFilename = WWW_ROOT.DIRECTORY_SEPARATOR.$filename;
}
}
And edit a the path to fit into my folder:
$AbsoluteFilename = $this->config_document_root.DIRECTORY_SEPARATOR.'cakephp'.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'webroot'.DIRECTORY_SEPARATOR.$filename;
$AbsoluteFilename = WWW_ROOT.DIRECTORY_SEPARATOR.'cakephp'.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'webroot'.DIRECTORY_SEPARATOR.$filename;
and now its working perfectly...

after try many things.. and finally read the answer of Jan Omacka, i only have to edit phpthumb.class.php, line 223 in the constructor function phpThumb()
First
// public: constructor
function phpThumb() {
.....
//comment line
//$this->config_document_root = (!empty($_SERVER['DOCUMENT_ROOT']) ? $_SERVER['DOCUMENT_ROOT'] : $this->config_document_root);
.....
}
//and put the constant CakePHP Var WWW_ROOT (Full path to the webroot.)
$this->config_document_root = WWW_ROOT;
//and if this don't work.. put your real path in linux, or windows
//$this->config_document_root = '/srv/www/htdocs/sic/app/webroot/';
In my case inside webroot, have a folder with estructure 'Usuarios/ID_Prestamo/IDUsuario/', all works great uploading the picture but thumbs not.. so after download the last version of phpThumb, i saw that show an error of File does not exist (URL misformat, for original JPG File), after that download the special versiĆ³n for CakePhp and change the lines as mentioned.. and all works... I use OpenSuse Linux, Apache2, with Cake 2.4.2
Notes: I verified that if not have zoomCrop it not works, this is my structure
'dir' => 'galeria/', //main folder webroot/galeria/
'createDirectory' => true,
'maxSize'=>'5 Mb',
'allowedExt' => array('.jpg','.jpeg','.png'),
'zoomCrop' => true,
'thumbsizes' => array(
'small' => array('width'=>165, 'height'=>115),
'medium' => array('width'=>800, 'height'=>600)
),

Related

Trouble Generating PDF with CakePHP and CakePdf

I am trying to use CakePdf to generate a pdf file within CakePHP. I have a function in the CourseGradesController called viewReport. I want viewReport to allow you to select a student from a select field, and then upon submitting the form, it will generate a PDF with the appropriate data. If I put the data into a table and do not try to make a PDF, the page will display correctly, so I don't think that is the problem. In bootstrap.php, I have
CakePlugin::load('CakePdf', array('bootstrap' => true, 'routes' => true));
Configure::write('CakePdf', array(
'engine' => 'CakePdf.WkHtmlToPdf',
'options' => array(
'print-media-type' => false,
'outline' => true,
'dpi' => 96
),
'margin' => array(
'bottom' => 15,
'left' => 50,
'right' => 30,
'top' => 45
),
'binary' => '/var/www/cakephp/app/Plugin/CakePdf/Vendor/WkHtmlToPdf',
'orientation' => 'landscape',
'download' => false
));
I have the WkHtmlToPdf folder moved into /var/www/cakephp/app/Plugin/CakePdf/Vendor/WkHtmlToPdf, so the lib and include folders are in that directory.
In the viewReport function of CourseGradesController, I have
function viewReport($id = null)
{
$this->CourseGrade->id = $id;
if (!$this->CourseGrade->exists())
{
throw new NotFoundException(__('Invalid invoice'));
}
$this->pdfConfig = array(
'orientation' => 'portrait',
'filename' => 'Invoice_' . $id
);
$this->set('invoice', $this->CourseGrade->read(null, $id));
...
}
If I navigate to /courseGrades/viewReport, I get the error "Error: The requested address '/cakephp/courseGrades/viewReport' was not found on this server."
If I naviate to /courseGrades/viewReport/1.pdf, then I just see a completely blank screen.
I would strongly recommend the use of this plugin for this kind of work.
https://github.com/ceeram/CakePdf

CakePHP Uploader Plugin only works on one Model

I've installed Miles Johnson's Uploader plugin and set it up with one of my models and got it working perfectly. Very nice.
Then I went and set it up on another model with almost identical code [the only difference is the upload path] and it won't work on the second model. When I submit the form the plugin doesn't seem to notice; I get an SQL error from an attempt to insert the POST file array straight into the DB.
Here is the code. [Other than this the plugin is imported in the bootstrap]
public $actsAs = array(
'Uploader.Attachment' => array(
'photo' => array(
'name' => 'formatFileName',
'uploadDir' => '/uploads/uses/img/',
'dbColumn' => 'photo',
'maxNameLength' => 30,
'overwrite' => true,
'stopSave' => true,
'allowEmpty' => false,
'transforms' => array(
array('method' => 'resize', 'width' => 240, 'dbColumn' => 'photo_thumb'))
)
),
'Uploader.FileValidation' => array(
'fileName' => array(
'extension' => array('gif', 'jpg', 'png', 'jpeg'),
'required' => true
)
)
);
This is on the model that is not uploading and the only difference is the uploadDir.
Does the plugin only work on one model? Any clues? thnx :}
Edit for extra clarity
Here is my view code:
echo $this->Form->create('Use', array('type' => 'file'));
echo $this->Form->input('Use.photo', array('type' => 'file'));
echo $this->Form->input('Use.desc', array('rows' => '3', 'label' => 'Description'));
echo $this->Form->end('Add to Gallery');
And here is my controller code:
public function add() {
if ($this->request->is('post')) {
$this->Use->set('user_id', $this->Auth->user('id'));
if ($this->Use->save($this->request->data)) {
$this->Session->setFlash('Your Use has been saved.');
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash('Unable to add your Use.');
}
}
}
The plugin doesn't work in only one model. You can add more uploader into your site.
The model seems to be good, I suggest you to see into your form to see if you have create the form in the right way into your view (is imporant to put into your form: 'type' => 'file'
example:
echo $this->Form->create('Product', array ('class' => 'form', 'type' => 'file'));
echo $this->Form->input('ModelImage.filename', array('type' => 'file'));
echo $this->Form->submit('Add Image', array('id'=>'add_image'));
echo $this->Form->end();
Or the problem is the name Use try to change the name with another
After checking thru the code with Alessandro [thank you :)] I found the problem.
If you look in the View and Controller code you can see that the model is named 'Use'. This was the problem, as Use is a loaded word in PHP and I shouldn't have used it for a model name.
I renamed the model to Outcome and now the Uploader works perfectly.

CakePHP view file via Media Views doesn't work

I have CakePHP 1.3 and I have an action that is supposed to view a file, the file maybe a .pdf, .doc, .... or any document, but I get a blank page instead.
code sample:
public function view_attachments($attachment_id){
$attachment = $this->get_attachment($attachment_id);
if($attachment){
$path = pathinfo($attachment['EmailAttachment']['file']);
$this->view = 'Media';
$this->autoRender = false;
$params = array(
'id' => $path['basename'],
'name' => $path['filename'],
'download' => false,
'mimeType'=> $this->Common->get_mime_content_type($path['basename']),
'extension' => strtolower($path['extension']), // must be lower case
'path' => APP . $path['dirname'] . DS // don't forget terminal 'DS'
);
$this->set($params);
}
}
Any Ideas? Please advise.
check that media.ctp file must be blank... to get proper output...
Thanks
Checking on my own working code, the only difference I see is
$this->autoRender = false;
Of course your not supposed to have a "view_attachments.ctp" file.
Be aware that browser's can't open ".doc" natively. So even if you want him to display it, he will offer you to download it.
function download($id) {
$data = $this->OdmPieceJointe->read(null, $id);
$path = pathinfo($data['OdmPieceJointe']['fichier']);
$this->view = 'Media';
$params = array(
'id' => $path['basename'],
'name' => $path['filename'],
'download' => false,
'extension' => $path['extension'],
'path' => 'uploads/',
);
$this->set($params);
}
maybe :
Configure::write('debug', 0);

Cakephp Error using Miles J Uploader plugin

I am currently trying to use Miles J plugin located here http://milesj.me/code/cakephp/uploader Although I have made great progress learning CakePhp, I am currently having a problem using the plugin and I would appreciate any help provided.
I have followed all the necessary steps to use the plugin. It has been downloaded put on Plugin folder, I bootstrapped with CakePlugin::loadAll().
So far so good.
Next I have proceed to set up the table as indicated by the plugin developer.
Ok, now back to my own code. I have the following set up:
images_controller.php , image.php and their views.
My goal now is to use the plugin inside those files as such:
App::import('Vendor', 'Uploader.Uploader');
Class ImagesController extends AppController {
var $components = array('Auth');
var $helpers = array('Design');
var $uses = array('Image', 'Uploader.Upload');
function manage(){
//here I show a simple upload form that uses the action saveimage
}
function saveimage(){
$this->Uploader = new Uploader();
if(!empty($this->data)){
$this->Upload->save($this->data);
}
}
}
Now, my model is set as follows
Class Image extends AppModel {
public $useTable = 'uploads';
public $actsAs = array(
'Uploader.FileValidation' => array(
'file' => array(
'extension' => array(
'value' => array('gif', 'jpg', 'jpeg'),
'error' => 'Only gif, jpg and jpeg images are allowed!'
),
'minWidth' => 500,
'minHeight' => 500,
'required' => true
),
'import' => array(
'required' => false
)
),
'Uploader.Attachment' => array(
'file' => array(
'name' => 'uploaderFilename',
'uploadDir' => '/files/uploads/',
'dbColumn' => 'path',
'maxNameLength' => 30,
'overwrite' => true,
'stopSave' => false,
'transforms' => array(
// Save additional images in the databases after transforming
array(
'method' => 'resize',
'width' => 100,
'height' => 100,
'dbColumn' => 'path_alt'
)
),
'metaColumns' => array(
'size' => 'filesize', // The size value will be saved to the filesize column
'type' => 'type' // And the same for the mimetype
)
),
'import' => array(
'uploadDir' => '/files/uploads/',
'name' => 'uploaderFilename',
'dbColumn' => 'path',
'overwrite' => true,
'stopSave' => false,
'transforms' => array(
array(
'method' => 'scale',
'percent' => .5,
'dbColumn' => 'path' // Overwrite the original image
)
)
)
)
);
}
}
On my model for testing purposes I have not changed anything but just copied and pasted the very same array as shown in the the Test/Model folder inside the plugin, which is meant to show the functionality of the plugin.
The following confusion, errors or lack of understanding is taking place:
My file is not being uploaded to the webroot/files/uploads folder
My data is being inserted in the database, but not in a complete manner by leaving empty as shown:
id | caption | path | path_alt | created |
4 | | | |2012:02:..|
Above, I expect the path to be saved, but it doesn't.
I have to admit my confusion comes mainly from my inexperience using plugins, so I am aware I might be doing something wrong regarding my models or my configuration.
Any prompt help would be appreciated greatly as I have tried to work this out on my own without any success.
A few things:
1 - In your controller you do not need to import the Uploader class. You also don't need to use the Uploader.Upload model (it's merely an example test case). All you need to do in the controller is call $this->Image->save() which will upload the file and save the path as a row into the database (if you defined the Attachment in Image).
2 - In your view, create the file input. Pay attention to the input name.
echo $this->Form->input('FILE_INPUT_NAME', array('type' => 'file'));
3 - In your Image model, setup the AttachmentBehavior and its options for that specific input field:
'Uploader.Attachment' => array(
'FILE_INPUT_NAME' => array(
'uploadDir' => '/files/uploads/',
'dbColumn' => 'path'
),
'ANOTHER_INPUT' => array()
);
Be sure that the column "path" exists in your images table. And thats it.
For more information on what each option does, check out the following: http://milesj.me/code/cakephp/uploader#uploading-files-through-the-model

ie wont support dtds in feed cakephp

Ok I'm trying to create a rss feed with cakephp rss helper for some post of an app. I followed the cakephp book to the letter and it wont work with internet explorer... When I open it with Opera it work but with ie it says "Internet Explorer does not support feeds with DTDs."...
I know microsoft is not supporting dtds because a security thread but how can I fix this issue? The company where I work uses ie by standard so changing the browser is not an option...
here is the code... So you can see there is not a mayor modification in it...
default.ctp
echo $this->Rss->header();
if (!isset($documentData)) {
$documentData = array();
}
if (!isset($channelData)) {
$channelData = array();
}
if (!isset($channelData['title'])) {
$channelData['title'] = $title_for_layout;
}
$channel = $this->Rss->channel(array(), $channelData, $content_for_layout);
echo $this->Rss->document($documentData,$channel);
index.ctp
$this->set('documentData', array(
'xmlns:dc' => 'http://purl.org/dc/elements/1.1/'));
$this->set('channelData', array(
'title' => __("Most Recent Hitos", true),
'link' => $this->Html->url('/', true),
'description' => __("Most recent Hitos.", true),
'language' => 'en-us'));
foreach ($posts as $post) {
$postLink = array(
'controller' => 'soportes',
'action' => 'view',
$post['Soporte']['id']);
// You should import Sanitize
App::import('Sanitize');
// This is the part where we clean the body text for output as the description
// of the rss item, this needs to have only text to make sure the feed validates
$bodyText = preg_replace('=\(.*?\)=is', '', $post['Hito']['actividad']);
$bodyText = $this->Text->stripLinks($bodyText);
$bodyText = Sanitize::stripAll($bodyText);
$bodyText = $this->Text->truncate($bodyText, 400, array(
'ending' => '...',
'exact' => true,
'html' => true,
));
echo $this->Rss->item(array(), array(
'title' => $post['Hito']['actividad'],
'link' => $postLink,
'guid' => array('url' => $postLink, 'isPermaLink' => 'true'),
'description' => $bodyText,
'dc:creator' => $post['Hito']['user_id'],
'pubDate' => $post['Hito']['fecha_sugerida']));
}
On a very basic level it might be because of the debug level in core.php - cake outputs the render time I think - you could try setting Configure::write('debug', 0); in your controller action to see if it renders in IE? I've had issues with XML / RSS and IE due to this before.

Resources