iNET Interactive - Online Advertising Agency
          
   Home    Authors    About    Login    Contact Us
   Search:   
Advanced Search     
  Articles

  ASP (26)
  ASP.NET (19)
  C and C++ (4)
  CFML (2)
  CGI and Perl (16)
  Flash (2)
  Java (7)
  JavaScript (28)
  PHP (92)
  MySQL (13)
  MSSQL (3)
  HTML (35)
  SEO (9)
  Visual Basic (12)
  CSS (13)
  SSI (5)
  XML (12)
  C# (14)

  Developer News

August 8, 2008
Reader Question: What graphics compression program do you use?
About
 
August 7, 2008
Google's Big Mistake: Getting Rid of Google Page Creator, What Do...
About
 
August 7, 2008
Wish XML a happy birthday
About
 
August 7, 2008
Poll: How important is SEO to your overal website strategy?
About
 
August 7, 2008
How to Create a Search Feature with PHP and MySQL
WebReference.com
 
August 7, 2008
1 comment
.net
 
Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /PHP /File Manipulation

File Managing 

  Views:    3840
  Votes:    4
by John Doe 11/26/03 Rating: 

Synopsis:

This small article will teach you how to manage files using the PHP technology.
Pages: 
The Article

File managing may help you through making dynamic applications. It consists of opening, reading and closing every kind of file.
You also can use files to store information without using any kind of DataBase, like MySQL, Oracle...

In this article you will learn how to build a small simple DataBase engine.

Lesson 1: Creating a simple form

Let"s create a simple form, so we have an easy way to get some info into our DataBase. We will use some HTML, but you can use your HTML editor to do the same thing.

<?php
echo "fill the form bellow with something";
echo "<br>";
echo "<form action=insert.php method=POST>";
echo "<textarea name=text></textarea>";
echo "<br>";
echo "<input type=submit value=ok>";
echo "</form>";
?>

Name this file form.php

Lesson 2: Inserting the text on the DataBase

We have the form, so now let's fill it and get some data in. Check www.php.net/fopen to see more information about the function we will use in the next example.

First, create a file called base.txt, with nothing inside. Just create it and upload it to your server, if you are using one.

<?php
// Open the DataBase source file, using the mode a+
$open = fopen("base,txt", "a+");

// Write to the DataBase
$sep = "<texts-separator>";

$write = fwrite($open, $sep.$text) or die("Could not write to the file");

// Close the DataBase source file
$close = fclose($open);

echo "Info was sent to the DataBase sucessfully!";
?>

Name this file insert.php, go to form.php and fill the form in with something.

Lesson 3: Reading files, showing our DataBase

Let's show what is inside the DataBase now.

<?php
// Open the DataBase source file
$open = fopen("base.txt", "r");

// Get the DataBase full content
$content = fread($open, filesize("base.txt"));

// Get result by result using <texts-separator>
$content = explode("<texts-separator>", $content);

// Calculate the total results
$total = count($content);

// Show the content
echo "<b>DataBase content:</b><br><br>";

for($i = 1; $i < $total; $i++) {
    echo "(".$i.") - ".$content[$i];
    echo "<br>";
}
?>

Name this file read.php

Make your tests now. Insert some info (form.php) and go to read.php! Very simple, right? You can change this script and make things like tag board, users registering, client info and much more!
Good Luck!

Pages: 

Similar/related articles:


 
  Sponsors