I have two HTML templates. And I buffer them into php email using ob_start() and ob_get_clean(). However, one can be sent without any problem while another has no images in the email body. Can anyone find what the problems are? Here are the two templates:
the good one: http://www.emoceanstudios.com.au/good.txt
the bad one: http://www.emoceanstudios.com.au/bad.txt
I have tried to use absolute path for images, and tried to use img tag instead of div with background image, but they don't work.
How about inline image? you can convert the img into data first. http://www.websiteoptimization.com/speed/tweak/inline-images/
You can try uploading images to cloud and use them from there....I am not sure...but may be this helps..!!! Also, remember putting ob_flush() in such cases.
You are using CSS in bad.txt file which path you have mentioned is given below.
link href="quote.css" rel="stylesheet" type="text/css"
so please mentioned your path with http://www.emoceanstudios.com.au/CSS/quote.css it is just a example but please provide full path to get Template as you want.
link href="http://www.emoceanstudios.com.au/CSS/quote.css" rel="stylesheet" type="text/css"
Related
I'm recently doing a website for a school project. In order to organize my work, I create a tree folder that keeps all the work organized. It is similar like this:
Back-Office
Pages
Home
home_test1.php
home_test2.php
home_test3.php
Login
Folder_Login
login.php
logout.php
Resources
CSS
style_home.css
style_navbar.css
style_footer.css
JS
script_home.css
script_navbar.css
Sections
navbar.php
footer.php
After all, with the require() method available in PHP, I want to call the "navbar.php" file to the "home_test1.php", "home_test2.php" and "home_test3.php", but the CSS style that is connected with the file "navbar.php" ("style_navbar.php"), doesn't display.
I've tried to change the path of the CSS style in the file "navbar.php" when I require() to the other file ("home_test1.php") and the CSS style shows up, but wont display in other file with a different path. How can I make this work dynamically? Sorry for long post and bad English grammar.
Thank you in advance.
You need to set your css and js files with absolute path instead of relative path
$dir = realpath($_SERVER["DOCUMENT_ROOT"]);
<link rel="stylesheet" href="<?php echo $dir.'/resources/css/style_home.css'; ?>" >
Without physically seeing you code it is quite hard to debug however there is an "obvious" answer that I'll suggest as a starting point.
The important thing to remember is that PHP and HTML are processed in completely different places. PHP executes on the server and should be used to build a full HTML "document" which it gives to the client/browser. The client/browser then reads the document provided and renders it according to HTML standards.
Calling require() will tell PHP to get the file and slot its contents directly where it was called and as it is a CSS file it will need to sit within the style tags. With a lot of modern browsers, if you use require on a file outside of the html tags, the content will be dumped at the top of the screen or simply ignored due to invalid syntax.
Alternatively if you would like to simply use tell the browser to include the CSS file, you could use the good old method of using <link rel="stylesheet" href="/path/to/file">. It's good to know when and when not to use PHP.
PS: You have .css files in your JS directory.
In PHP, there is a global variable containing various details related to the server. It's called $_SERVER. It contains also the root:-
$_SERVER['DOCUMENT_ROOT']
<?php
$path = $_SERVER['DOCUMENT_ROOT'];
<link rel="stylesheet" href="<?php echo $path.= '/Resources/CSS/style_navbar.css';?>" />
?>
I have a stylesheet link that looks like below:
<link rel="stylesheet" href="/example/get_page.php?location=bla.css" id="main_ss" />
get_page.php just gets a URL using file_get_contents():
if (isset($_GET['location'])) {
echo file_get_contents('/example/styles/' . $_GET['location']);
}
I can see that the stylesheet file is being fetched properly (for example the text of the file is showing in firebug when I expend the link tag) but for some reason it is ignored by the browser. If I just fetch the CSS file directly of course everything works.
The code can be seen here: www.specman-verification.com/example/bla.html
Any leads? I'm at loss here.
Add the Content-type header like this (do this before you output anything):
header("Content-type: text/css");
Your code is just trying to load the script get_page.php. To load the CSS file you need:
<link rel="stylesheet" type="text/css" href="/example/bla.css" />
(or similar depending on the actual path to your CSS file). In other words the href attribute needs to specify the path to your spreadsheet file, not the HTML page file.
You need to do it the right way. I understand what you're doing here. You need a good mechanism to dynamically load external CSS and have the result display normal html in the browser output.
Follow the instructions on this url: http://www.warpconduit.net/2009/05/12/dynamically-load-css-and-js-files-using-php/
This will at least get you to have a mechanism to load external css file with php dynamically. You're definitely missing steps in your code.
I set an icon like that:
<link rel="icon" type="image/x-icon" href="/media/icon.ico">
<link rel="shortcut icon" type="image/x-icon" href="/media/icon.ico">
and I also tried this:
<link href="/media/icon.ico" rel="shortcut icon" type="image/x-icon" />
It works only in some parts of my website, but I don't know what I'm doing wrong. Is there something that I have to consider?
I use PHP and HTML. I don't know if it's coincidence or not, but it works with every HTML file and only with some of the PHP files.
Can anybody help me?
shivan
You'll need to make sure the URL (href) is valid for the page you are viewing.
Remember / is site level (/media/icon.ico = http://yourdomain.com/media/icon.ico).
Also make sure it is a valid .ico file. I recommend trying a .jpg file instead. (.png, .jpg, .gif and .ico are all valid favicon formats)
As well, depending on the icon size, it may not work in all browsers.
16x16 is the recommend size for favicons, but 32x32 may work as well.
Here is a link that should tell you everything about favicons: http://perishablepress.com/everything-you-ever-wanted-to-know-about-favicons/
If it only appears for your html pages and not your php ones, then you may be adding the link tag incorrectly or it may also be missing.
I suggest you use the developer tools of your browser (right-click anywhere on your page and choose Inspect Element - Chrome, Firefox) when you're on your php pages and check if you see the tag added correctly having the exact same path set there as in your html pages. Using developer tools you should also be able to hover over the link and it would tell you if the image existed or not.
I bet the path will be incorrect somehow depending on the placement of your php files versus the html ones and the icon.
Try accessing those pages from another browser. Also, try accessing them from a browser in incognito/private mode.
If you do see the favicon, try cleaning your browser's cache - it could be that something is left over from the last time you browse those pages (i.e. before you added the favicon to the HTML).
I had trouble getting this to work for me without using a direct link.
For example on my site: http://adamgressen.com/
I reference the image with a direct link:
<LINK rel="SHORTCUT ICON" href="http://adamgressen.com/favicon.ico">
You definitely want to clear your cache if you're testing locally because you may not see the changes for a while otherwise.
I've been reading on this quite some time...and i'm puzzled -
Can you help on what is the difference between:
Yii::app()->clientScript->registerCssFile(Yii::app()->baseUrl.'/css/some-file.css');
<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/some-file.css
Is it a performance issue, or just different syntax?
Thanks,
Danny
registerCssFile always registers the file between the <head> tags, even if you call it somewhere in a view.
This is helpful if you care about HTML validation (a <link> in <body> is invalid), but still want to include a CSS file in a view.
registerCssFile actually aids performance, because the CSS is registered only when you want it (and need it).
The way you are using it, it is identical. To verify this, check the source of the page (in your browser) and check the statement that Yii::app()->clientScript->registerCssFile creates.
However, clientScript lets you control the position of the script in the HTML file. Check out: http://www.yiiframework.com/doc/api/1.1/CClientScript#registerScriptFile-detail and look for POS_HEAD, POS_BEGIN, POS_END.
What is probably more important is this: In the MVC philosophy, you want to have everything related to HTML-output in your view-file. Yii::app()->clientScript lets you add CSS and JS files from within your view files. And that is where you want it.
is there a way to style a php file with css so I can use border,padding, align and teother various
will this work or not if i added to the php or will i need functions for using this
<link rel="stylesheet" type="text/css" href="style.css" />
You cannot and probably will never be able to style a PHP file using css. What you want to style using css is the html content created using PHP and/or javascript! That is because styling takes place on the client machine in order to show things to the user while php gets executed on the server machine in orderf to produce code which will be readable by a browser.
<link rel="stylesheet" type="text/css" href="style.css" /> will work if the file style.css is found at that location (i assume your are using valid css definitions in your file)
You can use css to style HTML files. PHP generates HTML (or not) and you cannot style PHP files.
PHP doesn't know or care about CSS, and neither does it need to.
PHP runs on the server and does whatever it does, which should result in an HTML document.
This HTML document is send to the browser.
Only the browser cares about CSS, and it doesn't care whether an HTML document was just a file on the server's hard disk or whether it was created by PHP or magic fairies.
If the document the browser receives is an HTML document, you can use CSS with it. PHP has absolutely zero influence on this.
You don't style PHP with CSS. What's there to style? It's all just server-side code that generates HTML. You style HTML with CSS, not PHP.
If you are looking for a way to define styles in variables i.e. colour etc and make it easier to generate css try http://lesscss.org/
It's what I use to make css edits faster instead of copying and pasting.