For some reason I cannot view images in cakePHP 2.x, I have another cakePHP 1.3 running on the same machine and images are displaying perfectly for those.
I can get images by their full path.
However, I cannot access
http://localhost/app/webroot/img/image.png
If I use an image name that does not exist, then I get an error in Apache. So it does somehow see the image.
Thanks for your time.
$this -> Html -> image('add_row.jpg',
array(
'escape' => false,
'width' => '20',
'height' => '20',
'fullBase' => true,
'alt' => 'No Image'
)
)
Use "fullBase" attribute in the options array as it will get absolute path for the Image LINK. It might solve your problem.
Related
I am using the 'MeioUpload' plugin found here 'https://github.com/jrbasso/MeioUpload' and Cakephp 2.x.
Currently using this for single image uploads, please can anyone give advice on how to handle multiple image uploads using this plugin. Currently the db table storing the images holds filename, dir, mimetype and filesize fields for each image. I want to store more than one image for each of my posts when adding a new post. Any help would be much appreciated, thanks in advance :).
As I mentioned in my comment, you might want to try https://github.com/josegonzalez/upload as MeioUpload is now deprecated, and it's developer is working on that new upload plugin I linked to.
Either way, the following info for MeioUpload holds true for the new plugin, too.
MeioUpload is built to handle one uploaded file per corresponding set of fields. I don't think the example in MeioUpload's ReadMe is ideal, as it seems to imply that you have to have a table of 'images', where as in reality, you can have a table of just about anything, where each record holds one or more uploaded files (be it images, PDF's, MP3's... anything).
So, with that in mind, you have two solutions:
1) If your posts will have a potentially infinite number of images (ie, not a fixed, small number) then you can have Posts and Images in separate tables, and set up a hasMany relationship between them. See http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html
2) If you know that each post will only have a max of say 3 or 4 (or some other relatively small number) of images, then you can implement 3 (or 4, or X) sets of image fields in your Posts table / model, each to handle a separate upload. They'd be named, eg. featured_image_filename, feautred_image_dir, etc; image2_filename, image2_dir, image2_mimetype, etc; image3_filename, image3_dir, etc.
Your acts as would look something like:
var $actsAs = array(
'MeioUpload.MeioUpload' => array(
'featured_image_filename' => array(
'fields' => array(
'dir' => 'featured_image_dir',
'filesize' => 'featured_image_filesize',
'mimetype' => 'featured_image_mimetype'
),
),
'image2_filename' => array(
'fields' => array(
'dir' => 'image2_dir',
'filesize' => 'image2_filesize',
'mimetype' => 'image2_mimetype'
),
),
'image3_filename' => array(
'fields' => array(
'dir' => 'image3_dir',
'filesize' => 'image3_filesize',
'mimetype' => 'image3_mimetype'
),
),
)
);
This second solution is hardly ideal database design, but sometimes when you know there'll never be more than a few images, it's just the easiest way to do it - both in terms of developing, and in terms of an easy to use UI.
Make sense?
In my cakephp web page, I have a button that the user clicks and it performs some maintenance on the server and then presents a download to the user. The file download is testlogs.gzip but when the download option occurs in firefox, it comes up as a file type of html document.
The file downloads and extracts fine, but I want the file type to be correct.
Here is the Media view class for the download:
//$this->autoRender = false;
$this->viewClass = 'Media';
$params = array(
'id' => 'systemlogs',
'name' => 'testsystemlogs',
'download' => true,
'extension' => 'gzip',
// 'mimeType' => 'zip',
'path' => DS . 'home' . DS
);
$this->set($params);
I tried to add in the 'mimeType' => 'zip' but that did not work.
Any help would be great.
Thanks
UPDATE: I tested uploading of the same files and I used firebug to determine the content type. The only file types I care about are of type: application/octet-stream.
So I think I just need to set this type in the Media class settings, not sure how to do that though.
THanks
mimeType has to be specified as an associative array (extension -> type), in your case this would be array('gzip' => 'application/x-gzip'). CakePHP merges this array with the built-in array of known MIME types in CakeResponse class.
However, CakePHP already knows the MIME type of .gz files so changing the extension of your file, if it is an option, might be an even easier solution.
I'm searching for a way to add a field in a custom form that will allow me to upload a list of files like this one : which is a screenshot of a File field of the file module.
I tried this : http://ygerasimov.com/d7-zip-archive-custom-file-multiple-upload
which uses ajax and custom code. My files are saved in DB but not displayed when I reload the page... I tried to make it work but with no luck.
I really hope that someone will be able to help me.
Thanks in advance,
Hervé
You can used this for custom multiple upload fields:
$form['file'] = array(
'#type' => 'file',
'#name' => 'files[]',
'#title' => t('Upload some photos'),
'#description' => t('JPG\'s, GIF\'s, and PNG\'s only, 10MB Max Size'),
'#attributes' => array('multiple' => 'multiple'),
);
Seems simple but I can't figure it out. Every link on my website suddenly shows the path behind the link
Example:
Not a member yet? Please register(/users/register) to add your pitch.
I can't select the path with Firebug to trace where it is coming from. Anyone has an idea? Thanks
UPDATE:
The PHP code for this link is:
echo $html->link('register', array('controller' => 'Users', 'action'=>'register'));
I use the BluePrint CSS Framework
Your problem isn't the style rule. Your problem is that you are linking a print only stylesheet from blueprint as a normal (screen, projection) stylesheet.
You need to make sure your css link has 'media' = 'print' as one of it's attributes.
IE
<?php
....
echo $this->Html->css( array(
join( DS, array( 'blueprint', 'print' )),
'stylesheet',
array( 'media' => 'print' )
);
...
?>
Somewhere in the head section of your layout.
try this...
$this->Html->link(__('register', true), array('controller' => 'Users', 'action' => 'register'));
cakePHP v. 1.3
I would like to use the MeioUpload Behavior for uploading any kind of documents(I want every extension to be accepted). I've already seen this question , but it didn't work for me, for some strange reason I can only upload image and pdf files for the other types of files I get this error when I attempt to submit the form : "The post could not be saved. Please, try again."
Edit: Well, it looks like I was finally able to upload other kind of files apart from images,I had to write the options 'allowedMime' and 'allowedExt' in camelCase (in the documentation they use the underscore version 'allowed_mime', 'allowed_ext' I don't know why:( ), but I haven't been able to upload .zip files and most importantly I still don't know how to tell the behaviour to accept anything
var $actsAs = array(
'MeioUpload' => array(
'link_referencia' => array(
'dir' => 'files{DS}uploads',
'create_directory' => true,
'allowedMime' => array('application/pdf', 'application/msword', 'application/vnd.ms-powerpoint', 'application/vnd.ms-excel', 'application/rtf', 'application/zip'),
'allowedExt' => array('.pdf', '.doc', '.ppt', '.xls', '.rtf', '.zip'),
'default' => false,
)
)
);
Thanks in advance
It can be use for anything, hence it's called meioUpload and not meioImage
Just set the allowed file extensions and mime types when you initialiave the behavior.
Step 4 has an example http://www.meiocodigo.com/projects/meioupload/