File reading code2

This is a discussion on File reading code2 within the PHP General forums, part of the PHP Programming Forums category; Hi, Can someone make me an example of simple reading a *.txt file on a hard drive and displaying that ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-06-2007
Delta Storm
 
Posts: n/a
Default File reading code2

Hi,

Can someone make me an example of simple reading a *.txt file on a hard
drive
and displaying that file with a echo command or some loop or anything
path to file:

(C:\Program Files\XAMPP\xampp\htdocs\test_folder\test1.txt) btw the
script is in this folder to.

Full code please.


Thanks in advance!
Reply With Quote
  #2 (permalink)  
Old 01-06-2007
Peter Lauri
 
Posts: n/a
Default RE: [PHP] File reading code2

This just dumps the content to the browsers. You could use file() instead if
you want to loop thru every line.

$file = "test1.txt";

if(file_exists($file)) {
if(is_readable($file)) {
if($file_content = get_file_contents($file)) {
echo "<pre>";
echo $file_content;
echo "</pre>";
} echo "Something went wrong";
} else echo "Cannot read the file '$file', check permissions";
} else echo "The file '$file' does not exist in this directory";

You should learn how to read the manual, because in the end we will not do
this kind of things if it already is in the manual.

http://th.php.net/manual/en/function...t-contents.php

http://th.php.net/file

Best regards,
Peter Lauri

www.dwsasia.com - company web site
www.lauri.se - personal web site
www.carbonfree.org.uk - become Carbon Free



-----Original Message-----
From: Delta Storm [mailto:delta.storm@hi.t-com.hr]
Sent: Saturday, January 06, 2007 10:39 AM
To: php-general@lists.php.net
Subject: [php] File reading code2

Hi,

Can someone make me an example of simple reading a *.txt file on a hard
drive
and displaying that file with a echo command or some loop or anything
path to file:

(C:\Program Files\XAMPP\xampp\htdocs\test_folder\test1.txt) btw the
script is in this folder to.

Full code please.


Thanks in advance!

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:00 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0