Location: PHPKode > projects > Network Asset Management Archive > nama/liaso/uploadphonebook.php
<?php if ($HTTP_POST_VARS['action']) { ?> 
<HTML> 
<HEAD> 
<TITLE>File Upload Results</TITLE> 
</HEAD> 
<BODY BGCOLOR="WHITE" TEXT="BLACK"> 
<P><FONT FACE="Arial, Helvetica, sans-serif"><FONT SIZE="+1">File Upload 
    Results</FONT><BR><BR> 
<?php 
     
    $uploadpath = '/usr/local/apache/htdocs/phonedata/'; 
    $source = $HTTP_POST_FILES['file1']['tmp_name']; 
    $dest = ''; 

    if ( ($source != 'none') && ($source != '' )) { 

       $now = date("m/j/y h:i:s",time());
include "connect.php";
$row = 1;
$handle = fopen ($source,"r");
echo "<table border=2>";
echo "<th>Phone Ext</th><th>Name</th><th>Lab</th><th>Building</th><th>Room</th>";
$first = true;

while ($data = fgetcsv ($handle, 1000, ",")) {
    $num = count ($data);
    $num = 6;
    if ($data[0]!=0){
     if ($first == true) { 
          $stmtd="delete from phonebook;";
          $sthd=ibase_query($dbh, $stmtd) or die($stmtd);
          $first = false;
     }
     if ( (($data[0]>4819) && ($data[0]<4900)) ||
          (($data[0]>1999) && ($data[0]<4320)) ||
          (($data[0]>4370) && ($data[0]<4491)) ||
          (($data[0]>4569) && ($data[0]<4690)) )
       {
       if (($data[1]=='Primary') && ($data[9]=='Active')) {
          print "<tr>";
//          print "<td>$num</td><td>$row</td>";
          $row++;
          for ($c=0; $c < $num; $c++) {
             if ($c!=1){
              if ($c!=2) {
                    print "<td>" . $data[$c] . "</td>";
              } else {
                    $poscomma = strpos($data[$c],",");
                    if ($poscomma==0)
                    {
                       $myname=$data[$c];
                    } else {
                       $name = explode(",",$data[$c]);
                       $myname = $name[0] . ", " . $name[1];
                    }
                    $posdash = strpos($myname,"-");
                    if ($posdash!=0)
                    {
                       $name = explode("-",$myname);
                       $myname = $name[0] . " - " . $name[1];
                    }
                    $posdash = strpos($myname,"'");
                    if ($posdash!=0)
                    {
                       $name = explode("'",$myname);
                       $myname = $name[0] . "`" . $name[1];
                    }

                    print "<td>" . ucwords(strtolower($myname)) . "</td>";
                    $myname = ucwords(strtolower($myname));
                    $stmt="insert into phonebook (EXTENSION, NAME, OFFICESYM, BUILDING, ROOM) VALUES ('$data[0]','$myname','$data[3]','$data[4]','$data[5]');";
                    $sth=ibase_query($dbh, $stmt) or die($stmt);
              }
             }
          }
          echo "</tr>";
       }
     }
    }
}
fclose ($handle);
echo "</table>";
}
?> 
<BR><A HREF="<?php echo $PHP_SELF ?>">Back</A> 
</FONT></P> 
</BODY> 
</HTML> 
<?php } else { ?> 
<HTML> 
<HEAD> 
<TITLE>File Upload</TITLE> 
</HEAD> 
<BODY BGCOLOR="WHITE" TEXT="BLACK"> 
<P><FONT FACE="Arial, Helvetica, sans-serif"><FONT SIZE="+1">File 
    Upload</FONT><BR><BR> 
Pick phonebook file to import.
<BR> 

<FORM METHOD="POST" ENCTYPE="multipart/form-data" 
      ACTION="<?php echo $PHP_SELF;?>"> 

<INPUT TYPE="HIDDEN" NAME="MAX_FILE_SIZE" VALUE="800000"> 
<INPUT TYPE="HIDDEN" NAME="action" VALUE="1"> 
File 1: <INPUT TYPE="FILE" NAME="file1" SIZE="30"><BR><BR> 
<INPUT TYPE="SUBMIT" VALUE="Upload"> 
</FORM> 
</FONT></P> 
</BODY> 
</HTML> 
<?php } ?> 
Return current item: Network Asset Management Archive