Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 13th, 2007, 01:56 AM
Authorized User
 
Join Date: Feb 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default upload excel file in php4.2.2

Hi..!
I had code for upload excel file and come to know that i can only upload excel sheet(file) by changing it in xml first and then display or store in database. My upload window code is:
************************************************** ******************
                       //"upload.php"
<?

include 'config.php';
//file for username, ipaddress password ...etc to connect database(no required here).
include 'opendb.php';
//file to execuete mysql queries (no required here).

?>
<html>
<head>
<title>Upload File To MySQL Database</title>

</head>
<body>
<form action="import.php" method="POST" enctype="multipart/form-data">
  <table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
    <tr>
      <td width="246"><input type="hidden" name="MAX_FILE_SIZE" value="30000">
    <input name="file" type="file" class="box" id="file">

         </td>
      <td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
    </tr>
  </table>
</form>
</body>
</html>

************************************************** *****************

Code to upload that xml file is shown below-


************************************************** *****************

                        //"import.php"


  <?php
  $data = array();

  function add_person( $calldate, $calltime, $dialedno, $city, $calltype, $duration, $callrate, $amount )
  {
  global $data;

  $data []= array(
  'calldate' => $calldate,
  'calltime' => $calltime,
  'dialedno' => $dialedno,
  'city' => $city,
  'calltype' => $calltype,
  'duration' => $duration,
  'callrate' => $callrate,
  'amount' => $amount

  );
  }

  if ( $_FILES['file']['tmp_name'] )
  {
  $dom = DOMDocument::load( $_FILES['file']['tmp_name'] );
  $rows = $dom->getElementsByTagName( 'Row' );
  $first_row = true;
  foreach ($rows as $row)
  {
  if ( !$first_row )
  {
      $calldate = "";
      $calltime = "";
      $dialedno = "";
      $city = "";
      $calltype = "";
      $duration = "";
      $callrate = "";
      $amount = "";

      $index = 1;
  $cells = $row->getElementsByTagName( 'Cell' );
  foreach( $cells as $cell )
  {
  $ind = $cell->getAttribute( 'Index' );
  if ( $ind != null ) $index = $ind;

  if ( $index == 1 ) $calldate = $cell->nodeValue;
  if ( $index == 2 ) $calltime = $cell->nodeValue;
  if ( $index == 3 ) $dialedno = $cell->nodeValue;
  if ( $index == 4 ) $city = $cell->nodeValue;
  if ( $index == 5 ) $calltype = $cell->nodeValue;
  if ( $index == 6 ) $duration = $cell->nodeValue;
  if ( $index == 7 ) $callrate = $cell->nodeValue;
  if ( $index == 8 ) $amount = $cell->nodeValue;


  $index += 1;
  }
  add_person( $calldate, $calltime, $dialedno, $city, $calltype, $duration, $callrate, $amount );
  }
  $first_row = false;
  }
  }
  ?>
  <html>
  <body>
  <table>
  <tr>
  <th>calldate</th>
  <th>calltime</th>
  <th>dialedno</th>
  <th>city</th>
  <th>calltype</th>
  <th>duration</th>
  <th>callrate</th>
  <th>amount</th>
  </tr>
  <?php foreach( $data as $row ) { ?>
  <tr>
  <td><?php echo( $row['calldate'] ); ?></td>
  <td><?php echo( $row['calltime'] ); ?></td>
  <td><?php echo( $row['dialedno'] ); ?></td>
  <td><?php echo( $row['city'] ); ?></td>
  <td><?php echo( $row['calltype'] ); ?></td>
  <td><?php echo( $row['duration'] ); ?></td>
  <td><?php echo( $row['callrate'] ); ?></td>
  <td><?php echo( $row['amount'] ); ?></td>

  </tr>
  <?php } ?>
  </table>
  </body>
  </html>
************************************************** ********************



The excel file changed in xml, which is required to upload is below-
(this file is saved as with ".xml" extention with "xml spreadsheed type")



************************************************** ****************
calldate calltime dialedno city calltype duration callrate amount
10-Mar-07 10:10:10 99999999 sre std 1:01:01 2.4 135.9
11-Mar-07 11:11:11 88888888 ssw local 11:11:11 1.2 111.35
21-Mar-07 21:21:21 77777777 kanpur local 12:12:12 1.2 122.25

************************************************** ******************


This code is uploading means displaying properly, with php5.1 (which is installed on windows of my pc) but there is error in php4.2.2( which is installed in my office computer at which i work through telnet (my office machine os is windows-xp sp-2). mysql, apache and php4.2.2 is install on this machine.

NOTE: I read out that for php4, i have to use DOMXML i place of DOM and get_elements_by_tabname() in place of getElementsByTagName().
But i read the DOMXML page and come to know that there should have php4.3 version for DOMXML. So Please, someone tell me that can i use upload xml file through php4.2.2 What is syntex for using DOMXML through php4.2.2 , Please illustrate through my example or any other simple example....

Thank you....
rapraj@reddifmail.com
iit kanpur






Similar Threads
Thread Thread Starter Forum Replies Last Post
upload ms access file in php4.2.2 rapraj PHP How-To 0 April 17th, 2007 07:55 AM
upload file in php4.2.2 rapraj PHP How-To 0 March 6th, 2007 07:35 AM
hi have to upload excel file using jsp uttam.mca Pro JSP 3 July 14th, 2006 07:30 PM
To upload an excel file to to sql server. Abins ASP.NET 1.0 and 1.1 Professional 2 February 22nd, 2006 01:21 AM
Help! DTS to upload an excel file mauro_mtl SQL Server 2000 0 May 28th, 2005 03:41 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.