SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem in uploading .xml file

    Good day!

    I have code for uploading the files with the extension name .xml, after it was upload it will display in webpage and also save to database...

    My problem is during on my testing ...When I upload .xml file it did not upload, No error displayed...Sometimes when I upload it will upload, but theres a .xml file that did not upload, I cannot configured why it happens.

    here is the code:
    PHP Code:
    <?php
    $data 
    = array();


    $con mysql_connect("localhost""root","");
    if (!
    $con) { 
      die(
    mysql_error());
    }
    $db mysql_select_db("hris"$con);
    if (!
    $db) { 
      die(
    mysql_error());
    }

    $sql "select * from attendance";
    $result =  mysql_query($sql$con);
    if (!
    $result) {
        die(
    mysql_error());
    }
    $total mysql_num_rows($result);
    if (
    $total 0) {
        
    $sql "delete from attendance";
        
    $result =  mysql_query($sql$con);
        if (!
    $result) {
            die(
    mysql_error());
        }
    }
      
    function 
    add_employee($EMP_NO$Lastname$Firstname$Middlename$Date$Time)
      {
          global 
    $data
          
          
    $con mysql_connect("localhost""root","");
          if (!
    $con){ die(mysql_error());}
          
    $db mysql_select_db("hris"$con);
          if (!
    $db) { 
              die(
    mysql_error());
          }

          
    $EMP_NO $EMP_NO;
          
    $Lastname $Lastname;
          
    $Firstname $Firstname;
          
    $Middlename $Middlename;
          
    $Date substr($Date,0,-13);
          
    $Time substr($Time,11,-4);

          
    $Time strftime('%I:%M %p'strtotime($Time));


               
          
    $sql "INSERT INTO attendance (EMP_NO, Lastname, Firstname, Middlename, Date, Time) VALUES ('$EMP_NO', '$Lastname', '$Firstname', '$Middlename', '$Date', '$Time')";
          
    mysql_query($sql$con);
          
       
          
    $data []= array('EMP_NO' => $EMP_NO'Lastname' => $Lastname'Firstname' => $Firstname'Middlename' => $Middlename'Date' => $Date'Time' => $Time);
          
      }
      
      if ( 
    $_FILES['file']['tmp_name'] )
      {
          
    $dom DOMDocument::load$_FILES['file']['tmp_name'] );
                  
          
    $rows $dom->getElementsByTagName'Row' );
          global 
    $last_row;
          
    $last_row false;
          
    $first_row true;
          foreach (
    $rows as $row)
          {
              if ( !
    $first_row )
              {
                 
                  
    $EMP_NO "";
                  
    $Lastname "";
                  
    $Firstname "";
                  
    $Middlename "";
                  
    $Date "";
                  
    $Time "";
                  
                  
                  
    $index 1;
                  
    $cells $row->getElementsByTagName'Cell' );
              
                  foreach( 
    $cells as $cell )
                  { 
                      
    $ind $cell->getAttribute'Index' );
                      if ( 
    $ind != null $index $ind;
                      
                      if ( 
    $index == $EMP_NO $cell->nodeValue;
                      if ( 
    $index == $Lastname $cell->nodeValue;
                      if ( 
    $index == $Firstname $cell->nodeValue;
                      if ( 
    $index == $Middlename $cell->nodeValue;
                      if ( 
    $index == $Date $cell->nodeValue;
                      if ( 
    $index == $Time $cell->nodeValue;
                      
    $index += 1;
                  }
             
                  if (
    $EMP_NO=='' and $Lastname=='' and $Firstname=='' and $Middlename=='' and $Date=='' and $Time=='') {
                        
    $last_row true;
                  }      
                  else {
                      
                        
    add_employee($EMP_NO$Lastname$Firstname$Middlename$Date$Time);
                  }      
              }
              if (
    $last_row==true) {
                  
    $first_row true;
              }     
              else {
                  
    $first_row false;
              }
          }
      }
      
    ?>
      
      <html>
      <body>
      <table>
      <tr>
          <th>Employee Attendance</th>
      </tr>

      <?php foreach( $data as $row ) { ?>
      <tr>
      <td><?php echo( $row['EMP_NO'] ); ?></td> 
      <td><?php echo( $row['Lastname'] ); ?></td>
      <td><?php echo( $row['Firstname'] ); ?></td>
      <td><?php echo( $row['Middlename'] ); ?></td>
      <td><?php echo( $row['Date'] ); ?></td>
      <td><?php echo( $row['Time'] ); ?></td>
      </tr>
      <?php ?>
      </table>
      </body>
     </html>
    Thank you

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    How big are these files? You might be hitting the filesize limit.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  3. #3
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the filesize is 6,972kb

    but here is my upload code
    Code:
    <html>
    <body>
    <form enctype="multipart/form-data" 
      action="import_att.php" method="post">
      <input type="hidden" name="MAX_FILE_SIZE" value="2000000" />
      <table width="600">
      <tr>
      <td>Employee Attendance:</td>
      <td><input type="file" name="file" /></td>
      <td><input type="submit" value="Upload" /></td>
      </tr>
      </table>
      </form>
      </body>
     </html>

  4. #4
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by newphpcoder View Post
    the filesize is 6,972kb
    So. 6972 * 1024 = 7,139,328...

    <input type="hidden" name="MAX_FILE_SIZE" value="2000000" />
    2,000,000 vs 7,139,328....

    Yep. Think you might need to check your math there a bit.

  5. #5
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    So. 6972 * 1024 = 7,139,328...



    2,000,000 vs 7,139,328....

    Yep. Think you might need to check your math there a bit.
    So you mean I need to change thee value of my max_file_size???
    Thank you


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •