Displaying text from a text file in html - html

so i have a program that runs on a raspberry pi and outputs data to a text file. I'm wanting to try and display these outputs on a website i have already made.
so the goal is to have a text file (outputs.txt) and have the content from the text file be displayed on the website in the (outputs.txt(the text from the file)) tags
im going to be frank this probably makes no sense and made it even more confusing

html can't load any text file alone you need some server side language like php,java.net or javascript.In Php its very easy
<?php
$myfile = fopen("webdictionary.txt", "r") or die("Unable to open file!");
echo fread($myfile,filesize("webdictionary.txt"));
fclose($myfile);
?>
This will print the content of the file.

Related

Save pictures in document using Powershell and Word 2013

I'm trying to convert a HTML file with externally linked images to RTF using MS Word 2013 via Powershell commands, when using below command file gets converted however pictures are missing
$wrd = New-Object -ComObject "Word.Application"
$doc = $wrd.Documents.Open('c:\test.html')
$opt = [ref][Microsoft.Office.Interop.Word.WdSaveFormat]::WdFormatRTF
$name= [ref]'C:\test.rtf'
$wrd.ActiveDocument.SaveAs($name, $opt)
$wrd.ActiveDocument.Close()
$wrd.Quit()
If I do the conversion manually by opening the HTML file with Word and saving it as RTF same thing happens, no images, however if within Word I go to File, click on "Edit Links to File" and highlight all images, tick "Save picture in document" and then click on "Break Link" and then do the save as RTF, this time images are present within RTF (however with bad quality which is another issue..) [See picture below]
Is there a way to execute above process within Powershell?
Thanks
This does the job
$images = $doc.InlineShapes
foreach ($image in $images) {
$linkFormat = $image.LinkFormat
$linkFormat.SavePictureWithDocument = 1
$linkFormat.BreakLink()
}

Making on Offline form using JotForm

i'm a beginner and just learning about HTML. I just need a point in the right direction here. Any tutorials you can point me to would be greatly appreciated.
I am trying to create an offline version of this form I created on JotForm-http://form.jotform.us/form/40855701907154
I would like it to save the data a user inputs into an excel file.
I have tried saving the page offline by clicking 'save page as' but the 'submit' button doesn't appear.
I've been trying to understand this tutorial-http://diveintohtml5.info/offline.html.
Do I open the HTML file in notepad and try to edit it? If so, how do i edit it?
If you want to save the data to the Excel file.. you must store it first in database, then display your database in php with this header:
<?php
// excel raw data
header("Content-type: application/vnd-ms-excel");
// define the name "results.xls"
header("Content-Disposition: attachment; filename=results.xls");
// echo your database
include 'database.php';
?>
that is the simplest way for begginer... let me know if this work for you...

How to access image files outside project folder in html?

I put the user uploaded image files on separate disk partition on my local dev server(OS windows) which is outside of project folder. I need to access those image files in html pages of web app.
I tried out giving paths like: http://localhost:8080/C://tmp/thumbnails/pl_2001.JPEG but no help. Image is not fetched. How to properly access such files in html pages ?
You will have to use rewrites for this so you don't display sensitive folder names.
if you are using php you can use .htaccess rewrites for a slug something like images/someimage.mime and split/get what's after images/ and have a php function that takes the filename and makes sure it exists and if you want you can check if its a valid mime then send a header to say its a image/somemime so the browser can display the image instead of gibberish it will display without it.
$filename = "C://tmp/" . $file;
if(file_exists($filename)){
$img = getimagesize($filename);
if(in_array($img['mime'], array('jpg','jpeg','gif','png','etc'))){
header("Content-type: image/" . $img['mime']);
readfile($filename);
}else{
//default image
}
}else{
//default image
}
I haven't tested this but it should give you a idea on getting you started. If this isn't the language you are looking for try searching for something similar for your language you are using.

What do I have to do for opening and editing existing file with PHP?

I have different HTML files. I want to open, edit and then save changes with PHP (NOT OOP) in admin panel by using HTML textarea tag. What do I have to do for that? Do I need to create new mysql database? Could you please show me an example?
You can read the contents of the HTML file using file_get_contents:
$html = 'example.html';
$currentContents = file_get_contents($html);
// set the textarea text to $currentContents
To write the changes, you will have to post the textarea to a PHP script (through an HTML form) and then do something like:
$newContents = $_POST['textareaName'];
$html = 'example.html';
$fh = fopen($html, 'w') or die("File could not be opened.");
fwrite($fh, $newContents);
fclose($fh);
There are some security things you need to worry about it, but this is a basic example of how to achieve your goal. Good luck!
http://us.php.net/file_get_contents
http://us.php.net/fwrite

how to display image from upload directory on show.php page

Images are stored in the folder name upload in my website directory.
can anybody tell me how will i display it in another page name show.php
This question might be very basic level but I am very new to php.
Scan the directory for all image names and then output the image tag with the src set to the path for the image.
<img src="/upload/name-of-image-file-here" />
assuming the upload directory is web-accessible and whatnot. If not, then you'll need to do a script to handle the output of the image, of which there are plenty of sample questions/answers on this site.
You want to use PHP to scan the directory with the images in it and then generate HTML to show them.
You might want to look into the Directory Iterator object. You can use that to loop through the images and then generate the HTML as needed.
For getting files, you might want to use the following code (based on this PHP Documentation sample):
<?php
$iterator = new DirectoryIterator(dirname(__FILE__));
foreach ($iterator as $fileinfo) {
if ($fileinfo->isFile()) {
//Add filetype check here and then echo the HTML
echo $fileinfo->getFilename();
}
}
?>