I have two .png files that I would like to display along with some text in an html page that is being dynamically generated by Perl. In a perfect world this would be in a 3 column layout with the text in the first column and the two .png files in the second and third columns. The problem I keep coming across is the need for one of these tags:
print "Content-type: image/png\n\n";
print "Content-type: text/html\n\n";
I can only include one in the html and it means I can only display the text or the images but not both.
Obviously there must be a way to do this but so far Googling has gotten me nowhere.
Any advice is appreciated.
Regards.
Here are the print statements that I am using to generaate the dynamic html:
print "<html>";
print "<head>";
print "Content-type: text/html\n\n";
print "</head>";
print "<body>";
print "<table>";
print "<tr><td>Number of Sentences = $numSentences</td><td rowspan=\"4\"><img src=\"/home/kfarmer/public_html/kevin/charFreq.png\" /></td><td rowspan=\"4\"><img src=\"/home/kfarmer/public_html/kevin/charFreq.png\" /></td></tr>";
print "<tr><td>Number of Words = $numWords</td></tr>";
print "<tr><td>Number of Unique Words = $numUniqueWords</td></tr>";
print "<tr><td>Number of English Characters = $numEnglishCharacters</td></tr>";
print "</table></body></html>";
However, now when I generate this page I get a popup asking me how I would like to open the file -- and the file is just what I've printed above.
One HTTP response sends one thing, and each thing gets its own content header. You don’t need to include everything that will be in the page in one response.
From Perl, just link to the image files using the HTML features for that. In the HTML, you’d include:
<img src="url to PNG"/>
If there’s a CGI script serving up a dynamic image, you’d just link to it in the HTML:
<img src="/cgi-bin/imager.png?key=value;..."/>
That CGI script has to return the proper content type for what it’s sending back, whether HTML or image data.
The browser will interpret the HTML, see the links for the images, and make additional requests to get the images.
Your problem is more likely, that your images are absolute paths on the drive, rather than relative paths to the images on your websever.
I noticed that your img src is '/home/kfarmer/public_html/kevin/charFreq.png'
So, if your webserver's root is '/home/kfarmer/public_html/kevin' and that is what will load when you go to someurl.com, then your img src should just be '/charFreq.png'
If the root of your server is '/home/kfarmer/public_html' then your img src should be 'kevin/charFreq.png'
This is more complicated than that, as urls are relative to where the page is loaded from.
So, if the page is www.someurl.com/kevin/anotherfolder/mypage.html and you want to load an image in 'kevin/someotherplace/charFreq.png' then you need your img src to be either '/kevin/someotherplace/charFreq.png' OR '../someotherplace/charFreq.png'
I am afraid you are mixing up some definitions/technologies.
Context-type is part of the HTTP header. When your browser fetches a web page it normally uses HTTP, which consists of multiple header fields and a data block (for example containing the data which got requested). If you use a (decent) web-server you do not need to worry about HTTP headers (normally).
In order to show a 3 column page, with two (or any other number of) images and some text. You need to generate a HTML page. On this page you tell the browser that it should download the images and present them alongside the text.
In order to do, so you have to generate the HTML page in a pre-defined format containing so called elements:
<html>
<head><title>mypage</title></head>
<body>
This is the visible part of the page
</body>
</html>
Now in the body element, you can generate your text and images. The images can be placed onto the page using the img element.
Check out w3schools for more extensive tutorials on these subjects. If you gained some more basic knowledge, you can try to generate a HTML page using perl (or any other (scripting) language).
Related
Is it possible to embed HTML within a URL and then render that HTML in the browser itself?
In theory, what 'm thinking of works similarly to an URL like below:
http://"<h1>Hello World</h1>"
this would show a page with "Hello World" wrapped in a <h1> tag.
Of course, I understand that the above does not work in the real world for a wide range of reasons. Is there however a a way in which I can encode data within a URL and show render that data as HTML within the browser?
I understand that you could easily set up a webserver to do this, but I am interested in a solution which would work natively without any dependencies.
It's Data URL. Data URLs, URLs prefixed with the data: scheme, allow content creators to embed small files inline in documents. They were formerly known as "data URIs" until that name was retired by the WHATWG.
Data URLs are treated as unique opaque origins by modern browsers, rather than inheriting the origin of the settings object responsible for the navigation.
Syntax:
data:[<mediatype>][;base64],<data>
The HTML:
Test
This is what a data url does.
Go to welcome page
I purchased an email template and customized it to what I want, but now I'm stuck on how to send it.
The template file is an entire html page with included fonts and even a stylesheet at the top (styletags actually, not an attached file) with mediaqueries and some font settings.
Do I send all of that? Including header tags and more? It's basically an entire html page.
How part of my emailscript is build now:
$mail->isHTML(true);
$texts = 'html template';
$mail->msgHTML($texts);
But I haven't tested my own code yet because the template file is full of single quotes and double quotes. So the variable doesn't like that, I tried replacing all single quotes to double quotes in the templatestring but then my fonts are not working anymore (I tested remotely using this site: https://putsmail.com/).
PHPMailer itself doesn't do anything special with HTML content (though msgHTML reads your content to make a rough plain-text version). It sounds like you're just having trouble quoting inline content. You might like to try a different form of quoting called nowdoc which will tolerate all kinds of quotes without a problem:
$texts = <<<'EOT'
html template
EOT;
$mail->msgHTML($texts);
You could also save it in an external file and read it in when you need it, which also avoids quoting issues:
$mail->msgHTML(file_get_contents('template.html'));
I'm making an api call to a site using the code as shown below :
$xmlData = file_get_contents("http://isbndb.com/api/books.xml?access_key=XXXXXX&index1=isbn&value1=0596002068");
echo $xmlData;
However xmlData when displayed on the browser is auto parsed to HTML. For e.g. The element <title> of the returned XML which is actually a book title is converted to HTML essentially becoming the page title, and the other XML elements are displayed as plain text without the tags. I want the client side XMLHttpRequest Object to get raw XML data from the server side.
Why does this happen and how do I ensure that XML is not auto parsed?
PHP just sees it as text. For instance, do echo "<b>Bold</b>"; and it will "automatically" be in bold. It is the browser that processes the HTML and renders it.
This is what htmlspecialchars is for.
This got nothing to do with php. you spit out elements which browser interprets as HTML (that's why it sets title). Build your html page right, use <pre> tags around your content, or. when needed, send your content with correct content-type header (like text/plain to display your xml for viewing or text/xml for other purposes) so it will not parse your data as html.
I have an HTML page which needs to display some HTML generated by the user on the Administration area (like a blog, for instance). The problem is that the user sometimes needs to copy-paste tables and other "garbage" content from Word/Excel to the WYSIWYG editor (that has the proper "paste from Word" function). This causes the resulting HTML code to be very dirty.
It wouldn't be a problem unless some of these pages are shown totally wrong: other divs AFTER user's HTML code are not in their supposed position, floats are not respected... etc...
I tried putting a div:
<div style="clear: both;"></div>
without success. I even tried with iFrames, but iFrames accept only external webpages (if applicable...).
The question is: is there any tag or method to put a part of an HTML code inside a webpage discarding all formatting AFTER this code?
Thank you.
To my knowledge, you simply want to end all divs. HTML is a very simple code, with very simple options. Your example doesn't work because HTML isn't that advances. You can either start a function <...> or end a function .
Ideally what you want is a piece of code that puts their work in a separate frame entirely, so as soon as the page passes their code, it goes back to the correct formatting.
Or, you could be really sloppy and put one hundred 's in, just in case.
I'm building a custom print template closely following the directions in Chuck Ainslie's articles. One thing I'd like to do is generate a table of contents on the fly with the actual page numbers.
Is there any way too find what part of the document a layoutrect instance contains? Basically, I want to scan the original document for specific tags (say <h1> tags), then figure out which layoutrect contains those tags. From there I can figure out which devicerect is the parent and that tells me the page number.
During the layout, when the onLayoutComplete handler is called, there doesn't seem to be any way to get the source of what was actually laid out.
I managed to generate a dynamic table of contents (dynamic in the sense that the page numbers are collected at print time and are not in the static html page). It isn't pretty though.
I couldn't find any way to determine what part of my document was being flowed into the specific device and layout rects. Instead, I break my document up into individual html files, one for each section. To print, I create an html file that looks roughly like this:
<html>
<body>
<h1>Table of Contents</h1>
<table>
<tr><th>Report</th><th>Page</th></tr>
<tr><td>Foo</td><td>0</td></tr>
<tr><td>Bar</td><td>0</td></tr>
<tr><td>Etc</td><td>0</td></tr>
...
</table>
</body>
</html>
Rather than send that document to the printer, my print template pulls out all the section URLs from the document object. It then sends each of these to the printer and for each, it tracks the page number the section is printed on. When printing is complete, it updates the original document and replaces the '0' placeholders with the actual page numbers. Then the table of contents is printed.
It's not very elegant and now I have to add the rest of the UI around my print template code.