how to use new image folder in cakephp - cakephp

I have created a folder in app/webroot/. for image placing. eralier by default img folder cantain image. which I have used some thing like this:
<?php
echo $html->image('foldopen.png',array('width'=>14,'height'=>'10','alt'=>'open'));
?>
now I have created new image folder insted of img folder. how to use this?

use a slash at the beginning of the path. For example
echo $html->image('/images/foldopen.png');
Using the slash at the start is relative to the app/webroot directory

Just create your folder in webroot folder (test) and use like this:
echo $this->Html->image('/test/image.jpg');

I created one images folder in webroot dir. I used
$this->Html->image('../images/profile_image.jpg');
in my cakephp2.1 application. this worked for me.

or you can just change the App.imageBaseUrl in app/Config/core.php

If you want to keep your $html->image() statements short and modify the default image route you could always override the default behavior of image() by altering the config/tags.php file.
more info on changing the tag output

Related

How to get folder path runtime

I am new to java.
I am using this code
MyClass.class.getClassLoader().getResourceAsStream("myfile.properties")
to the values from property file.
Now i am storing the webdriver in a folder under project, would like to get the path dybamically, so im using this code:
MyClass.class.getClassLoader().getResourceAsStream("Drivers\\IEDriverServer_x64_2.50.0.zip")
but this returns null, can any one suggest me how to read the file/folder located under the project?
First of all check the location of the file you want to load inside the JAR and try using relative paths like
MyClass.class.getClass().getResourceAsStream("/yourFolder/myfile.properties")
OR
MyClass.getClass().getClassLoader().getResourceAsStream("/yourFolder/myfile.properties")

cakephp Managing Plugin Views how to determine paths

I have a plugin installed that has its own layout overrides for different controllers. However I'm having trouble understanding the mechanism for modifying the paths.
In the plug-in controller if I tell it to use my layout
$this->layout = 'default_dashboard';
Which is in app/Views/Layout and references an image in app/webroot/default_images.
All the relative links work fine to default_images when I do this, but would like to use some of the Plugin template overides for other actions.
However if I modify the default.cpt file to include some of the images, like say a logo that is used in default_dashboard.ctp. It is unable to map to the same image location.
For example in default.ctp:
echo $this->Html->image('default_images/logo.png',array('alt' =>
'Logo','width'=>'284','height'=>'82'));
produces a path to /img/default_images/logo.png. The Plugin is configured to use the /img location, whereas I want to direct to /default_images in this case. I could make this ../default_images/logo.png, but this isn't very clean.
In addition I have js and css which is having a similar problem. Can someone please explain the mechanism for using a site-wide default.ctp so that it works with inherited plugin templates?
From hard coding the links into the template not using the Html Helper, I see that the browser's relative path is confused because of the routing. For example the first one works with the root specified, the second doesn't.
<img src="/default_images/logo.png" alt="works" width='284' height='82'>
<img src="default_images/logo.png" alt="lost" width='284' height='82'>
What's the best way to make sure that the Plugin layouts and non-plugin layouts can all find the correct path to /default_images ?
Following are the steps that you can follow to resolve relative path problem:
Create a file abc_constants.php in app\Config folder.
Include the file in app\Config\bootstrap.php
require_once(abc_constants.php);
abc_constants.php should contain:
define('HTTP_HOST', "http://" . $_SERVER['HTTP_HOST'].'/');
define('SITE_URL', HTTP_HOST.'your_app_name/');
define('IMAGE_HTTP_PATH', SITE_URL.'app/webroot/default_images/');
Use these constants in your view file accordingly.
<?php echo $this->Html->image(IMAGE_HTTP_PATH.'logo.png',array('alt' => 'Logo','width'=>'284','height'=>'82'));
It looks a bit lengthy process at first time, but once implemented, you can use these constants in Ajax calls in view files, controller's code etc.

How do I delete a file?

I need to delete a picture from a folder where pictures are stored. For example, a file in the C:\Milk\Pictures folder. How do I do this?
Using the SysUtils function DeleteFile:
if DeleteFile(FileName) then
// File deleted;
SysUtils is usually included by default. In XE2, if you have to add it you may have to use System.SysUtils because of new namespace rules.

cakephp 1.3 favicon

I am using cake 1.3 and i had tried to implement favicon..But some strang error happens and sometime its showing favicon but for sometimes its not showing it.Pronlem is cakephp img folder path is changing>How can i escape from this problem.
i have used below code in my default.ctp
<?php echo $this->Html->meta('favicon.ico','../../app/webroot/img/favicon.ico',array('type' => 'icon'));?>
Favicon shows for following url.
http://localhost/finalportal/index.php/events/eventlist
Favicon not showing for followin url
http://localhost/finalportal/index.php/productsServices
I had tried this also.
<?php echo $this->Html->meta('favicon.ico',/favicon.ico',array('type' => 'icon'));?>
in this case favicon path is not correct
What i am doing wrong
meta('favicon.ico',$this->webroot.'img/favicon.ico',array('type' => 'icon'));
It works perfectly, just create favicon.ico image in img folder.thats it.
Don't use relative paths in the HtmlHelper, Cake prepends the correct path for you.
I haven't use the meta function, so I'm not sure if it respects the Cake directory conventions (e.g. images are in img, JavaScripts in js), but this should work:
<?php echo $this->Html->meta('favicon.ico','/img/favicon.ico',array('type' => 'icon'));?>
use following code to get right path.
<?php echo $this->Html->meta('favicon.ico',$this->webroot.'img/favicon.ico',array('type' => 'icon')); ?>
The problem in the first version is that you're using relative paths so it will always end up pointing to the wrong place, depending on how many parameters the URL has. ../../app/webroot means "two levels down, then to directory app/webroot". Two levels down from http://localhost/finalportal/index.php/events/eventlist is http://localhost/finalportal/index.php/, but two levels down from http://localhost/finalportal/index.php/productsServices is http://localhost/finalportal/, so you end up in the wrong place.
The reason why the second method (which is syntactically correct) doesn't work is probably because you have the server set up wrong. Apache's DocumentRoot should point at the app/webroot directory or the .htaccess file in the root directory should redirect requests to app/webroot.

Linking to a file (e.g. PDF) within a CakePHP view

I'd like to link to some PDFs in one of my controller views. What's the best practice for accomplishing this? The CakePHP webroot folder contains a ./files/ subfolder, I am confounded by trying to link to it without using "magic" pathnames in my href (e.g. "/path/to/my/webroot/files/myfile.pdf").
What are my options?
EDIT: I didn't adequately describe my question. I was attempting to link to files in /app/webroot/files/ in a platform-agnostic (ie. no mod_rewrite) way.
I've since worked around this issue by storing such files outside the CakePHP directory structure.
$html->link('Pdf', '/files/myfile.pdf');
This is somewhat tangential, but for access to such a location in Models and other places you can simply do this:
$file = WWW_ROOT . DS . 'files' . DS;
This tactic might be helpful to someone accessing files for static data loading, such as XML or JSON.
This is not recommended for public consumption or public linking.
I can confirm that this is an issue when mod_rewrite is not being used.
<?php echo $html->link('pdf', '/files/test.pdf'); ?>
outputs
pdf
it should output
pdf
This should work
<?php echo $html->link('pdf', $this->webroot('files'.DS.'test.pdf'); ?>
I'm not sure I understand the question correctly, but here goes. Basically any file you put in the webroot folder will be accessible on the webserver, so if you put the file in webroot/files/file.pdf you would simply link to /files/file.pdf.
If that doesn't work, please clarify your question...
or..
Link Text
:)
or...
Link Text
Descargar Archivo

Resources