View Full Version : News Content from Texts uploads
wrathyimp
09-24-2012, 06:59 AM
Hi,
I am new to the web development, my client is looking for a simple way to upload news to his website (static/HTML), were he just upload a text file with his news content, and his site updates the news pages, basically in 3 different areas: News Portlet (Home Page), Our News page, And the News Page itself.
SO if he uploads file like "news17.text" it will be the latest news, which will be shown on the home page with link (read more) to the news page, and will also have similar content on the our news page with read more link.
So how can i make such a setup, through googling i have understood, in need ajax, or server-side includes; but I am not getting exact scripts that helps me in my scenario.
Thanks
bernie1227
09-24-2012, 07:30 AM
one option, is to use php to open the textfile and print out it's contents onto the site.
wrathyimp
09-24-2012, 10:06 AM
Is there any script for it. I dont know any thing on PHP.
bernie1227
09-24-2012, 11:18 AM
You'd just use the fopen function on the file and then echo the contents into a div
wrathyimp
09-24-2012, 11:29 AM
But then I have to change all my sites from .html to .php
djr33
09-24-2012, 01:21 PM
Yes, you would. But it's worth it. That's the best way to do this. PHP isn't the only option. ASP, SSI and a few others are possible as well. It depends on what you want to learn and what is available on your server. PHP is most likely to be available and useful to you, but it's up to you (and your server).
Also, I'd probably look into putting all of this into a database if I were you, but that's not necessarily required if this content isn't going to change very often and you don't mind managing the files as you've described.
You could use Ajax instead, but it might actually be more difficult.
Simply put, you're going to learn something new in order to do this. It's not an especially difficult task broadly speaking, but it's going to be challenging if it's the first time you've done something like this.
(Also, changing all of your files from .html to .php is the least of your concerns. If that's what it takes, then just do it. But you can actually get around that if you really need to, by telling your server, probably via .htaccess, to treat .html as PHP code-- not my recommendation but possible. Ask if you need more information on that.)
bernie1227
09-24-2012, 09:04 PM
this (http://www.tizag.com/phpT/fileread.php) is a good tutorial on reading files with php. I agree with Daniel, it is very worthwhile learning some sort of server-side scripting language.
wrathyimp
09-25-2012, 07:08 AM
Thanks Daniel, Can give nore info on the ajax you have mentioned.
Bernie, i will try the tutorial.
bernie1227
09-25-2012, 08:15 AM
personally, I'd go for a server-side language such as ASP, PHP or Python rather than just Ajax, as when it comes to databases and other components of server-side computing, you would probably want to learn some of these in order to do all of that.
jscheuer1
09-25-2012, 09:23 AM
I'm still a little unclear what the three pages are. How is Our News Page different from the News Page itself. If all of each story is to be on one of those pages and only snippets on the others, I think that the biggest challenge would be creating the snippets and linking them each to their respective full story counterparts.
An XML file like is used in an RSS feed might be good.
bernie1227
09-25-2012, 09:34 AM
Well, I'd suggest splitting each part of each news story with a delimiter so you can split them into parts.
wrathyimp
09-26-2012, 10:26 AM
Bernie, can you explain which part to split, like different text files for each snippets or from the same file we define each part based on word/character count.
bernie1227
09-26-2012, 10:40 AM
well, in the php, you would use fopen() to open the text and store it in a variable, but when you had written the text, in the .txt file, between the entries, you put a delimeter, say just some specific character or set of characters. What wou would do then, is use the php explode() function to split the variable at a delimeter giving you each entry in an array, which you can then print onto the array.
for the snippet part when you have each entry in the array, you could store the snippets in another array using the substr() function to only get the amount of chars you want.
Beverleyh
09-26-2012, 04:34 PM
Maybe this kind of thing will get you started?: http://jemthingsandstuff.co.uk/testing/text-files-news/home.php
I've attached a zip of the sample files - the individual news text files are numbered sequentially with the biggest number currently sorting to the top.
4772
wrathyimp
09-26-2012, 05:29 PM
Thanks,
This is similar to What I was looking for.
On the Home.php, we have news at the bottom give "Sorry - no news previously selected." Whats the purpose of it?
Beverleyh
09-26-2012, 05:55 PM
Just to illustrate that the link/url without the news number query string returns an empty result.
You'll notice that the read more's use the same news page but take the query string number to load in the corresponding text file.
You should still include the empty string read out though to let users know when something went wrong - if there's anything that *can* go wrong, average-Joe is going to find it! :)
bernie1227
09-26-2012, 08:46 PM
See here for information about explode() (http://php.net/manual/en/function.explode.php)
And here for information about substr() (http://php.net/manual/en/function.substr.php)
wrathyimp
09-27-2012, 05:35 AM
Thanks Again Beverleyh, But I need a similar script to add to my html pages.
Beverleyh
09-27-2012, 06:33 AM
Like Dan said earlier (in the post that you 'officially' thanked) you can get the server to treat html pages as php with .htaccess - here's how to do that: http://www.besthostratings.com/articles/php-in-html-files.html
There are variations in the comments that you can try in case the solution in the main article doesn't work.
Also, if you're unsure how to setup .htaccess, you literally just create a file called " .htaccess " at the root of your website amd paste in the suggested code.
Hope that helps
djr33
09-27-2012, 06:48 AM
This is certainly possible; but it's usually not necessary. If you look at the site from a bigger perspective, the right answer is probably to create .php files instead. I don't really understand the reason you're avoiding it.... but... it's your site :)
Beverleyh
09-27-2012, 07:11 AM
I agree - I'm with Daniel on the bigger picture too - changing the extensions to php and then 301 redirecting the html pages to their new php locations is what I'd personally do in your situation.
The html-as-php fix is really just an optional workaround because you seem to have your heart set on keeping the pages as html. Not the *best* solution - just *a* solution (if your server is set up that way)
wrathyimp
09-27-2012, 07:23 AM
Its not my requirement, but its my clients, and they are hosting on NetworkSolutions. If i move to php, then have to change all my links and page extensions. But I am assuming the NetSol might be having the "AddType application/x-httpd-php .html .htm" in the websites .htaccess.
djr33
09-27-2012, 07:40 AM
Are you sure that PHP is available on the server? That's the first requirement, before anything else. (Not sure if you've already looked into this.)
PHP is often available, but isn't on every server (or might be disabled).
The way to test is the following-- create a page called "test.php" with exactly the following in it (only!):
<?php phpinfo(); ?>
If you don't see anything or get a weird error message, PHP isn't working. If you see a list of PHP features (version number, extra installations, server information, and much more) then PHP is working and that's all the info you'll need to figure anything out about how PHP is setup on this server.
If i move to php, then have to change all my links and page extensions.Right. We've all done this once or twice. It's really a good idea and can save you time later. But... up to you.
wrathyimp
09-27-2012, 07:44 AM
I have checked the attachments provided by Beverleyh, uploaded on their server, and they were working fine.
We've all done this once or twice.
What did you meant?
Beverleyh
09-27-2012, 07:51 AM
I think Dan means having to back-track over your static/coded links and update them all manually ;)
Oh yes I've been there!! :) Its a good learning curve though and maybe the push to now name your future projects with the php extension so you have more options available as your sites evolve?
Good luck with the news updates.
djr33
09-27-2012, 07:53 AM
Ok, glad that PHP is working on the server.
Yes, I meant moving from HTML to PHP (in various ways, but including the very long process of renaming all of the ".html" references to ".php" references) :)
wrathyimp
09-27-2012, 07:54 AM
Now I will start working on the news and their text files from this Weekend. So will be around posting on this thread for furture queries and suppport, hope you GURUs dont mind.
Beverleyh
09-27-2012, 08:39 AM
Not at all :)
a few more of those official thanks credits would sweeten the deal for those giving the help though ;)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.