Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 13th, 2007, 01:56 AM
Authorized User
Join Date: Feb 2007
Location: IIT Kanpur, UP, India.
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default upload excel file in php4.2.2

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:
************************************************** ******************

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).

<title>Upload File To MySQL Database</title>

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

      <td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>

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

Code to upload that xml file is shown below-

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


  $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;
  <?php foreach( $data as $row ) { ?>
  <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>

  <?php } ?>
************************************************** ********************

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....
iit kanpur

Reply With Quote

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 On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 10:48 AM.

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