Lesson 10 file system using PHP.

The task is to input a drive name ,folder name , file name, file contents and file extension from the user and save it into the server hard drive.we will learn some php file handling function here.
Program :
/*php  file system scipt */
if(isset($_POST['submit'])) {
   $errors=''; //an null string
   if ($_POST['folder']=="") {
   $errors.= "<li>Please give a folder name</li>";
    if ($_POST['file]=="") {
   $errors.= "<li>Please give a file name</li>";
    if ($_POST['text]=="") {
   $errors.= "<li>Please give a file contents</li>";
   if ($errors=='') {
   $path = $_POST['drive']."/".$_POST['folder'];
   if  (!file_eixsts( $path)) {
  $file_path = $path."/".$_POST['file'].$_POST['ext'];

    if  (!file_eixsts( $file_path)) {
    $fp = fopen($path,"w");  //opening file in write mode at the given path and return a pointer to it.
    fwrite($fp,$_POST['text']); // writing file to directory
   echo "Your file has benn saved.";
   echo "<br/>";

   echo "file exists already, try again";
echo "<ul>".$errors."</ul>";


<title>PHP file handling</title>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" name="form"><
<td>Drive name</td><td><select name="drive">
<option name="c:\">C:\</option>
<option name="d:\">D:\</option>

<td>Folder name</td><td><input type="text" name="folder" /></td>

<td>File name</td><td><input type="text" name="file" /></td>

<td>File contents</td><td><textarea name="text" cols="4" rows="15"></textarea></td>

<td>File type</td><td><select name="ext">
<option name=".txt">*.txt</option>
<option name=".html">*.html</option>
<option name=".ppt">*.ppt</option>
<option name=".doc">*.doc</option>


<td>&nbsp;</td><td><input type="submit" name="submit" value="save" /></td>


Hopefully the information we provide can be useful.

Press ESC to close