473,385 Members | 1,927 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to update page after a file is uploaded?

15
I am trying to make a site available for someone to *upload* certain type of text file (.txt) that can be parsed by written code. the upload file is available on the main site but I need this to result in different page on the right as someone clicks on SUBMIT with one's file attached. The uploaded file by clicking submit button should be PARSED on the right side of the page but when I click on the submit with the file now, it goes to the local host main page. I don't know what I have to do. This is what I currently have on the website, below picture!



the code is what I currently have for the THEME folder for Drupal page. Line 39-45 is what I wrote for the uploading file part.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // $Id: page.tpl.php,v 1.28.2.1 2009/04/30 00:13:31 goba Exp $
  3. ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml" lang="<?php print $language->language ?>" xml:lang="<?php print $language->language ?>" dir="<?php print $language->dir ?>">
  5.  
  6. <head>
  7.   <?php print $head ?>
  8.   <title><?php print $head_title ?></title>
  9.   <?php print $styles ?>
  10.   <?php print $scripts ?>
  11.   <script type="text/javascript"><?php /* Needed to avoid Flash of Unstyle Content in IE */ ?> </script>
  12. </head>
  13.  
  14. <body>
  15.  
  16. <table border="0" cellpadding="0" cellspacing="0" id="header">
  17.   <tr>
  18.     <td id="logo">
  19.       <?php if ($logo) { ?><a href="<?php print $front_page ?>" title="<?php print t('Home') ?>"><img src="<?php print $logo ?>" alt="<?php print t('Home') ?>" /></a><?php } ?>
  20.       <?php if ($site_name) { ?><h1 class='site-name'><a href="<?php print $front_page ?>" title="<?php print t('Home') ?>"><?php print $site_name ?></a></h1><?php } ?>
  21.       <?php if ($site_slogan) { ?><div class='site-slogan'><?php print $site_slogan ?></div><?php } ?>
  22.     </td>
  23.     <td id="menu">
  24.       <?php if (isset($secondary_links)) { ?><?php print theme('links', $secondary_links, array('class' => 'links', 'id' => 'subnavlist')) ?><?php } ?>
  25.       <?php if (isset($primary_links)) { ?><?php print theme('links', $primary_links, array('class' => 'links', 'id' => 'navlist')) ?><?php } ?>
  26.       <?php print $search_box ?>
  27.     </td>
  28.   </tr>
  29.   <tr>
  30.     <td colspan="2"><div><?php print $header ?></div></td>
  31.   </tr>
  32. </table>
  33.  
  34. <table border="0" cellpadding="0" cellspacing="0" id="content">
  35.   <tr>
  36.     <?php if ($left) { ?><td id="sidebar-left">
  37.       <?php print $left ?>
  38.  
  39. <form action="test_0512.php" method="post"
  40. enctype="multipart/form-data">
  41. <label for="file">Upload the file: </label>
  42. <input type="file" name="file" id="file" /> 
  43. <br />
  44. <input type="submit" name="submit" value="Submit" />
  45. </form>
  46.  
  47.  
  48.     </td><?php } ?>
  49.     <td valign="top">
  50.       <?php if ($mission) { ?><div id="mission"><?php print $mission ?></div><?php } ?>
  51.       <div id="main">
  52.         <?php print $breadcrumb ?>
  53.         <h1 class="title"><?php print $title ?></h1>
  54.         <div class="tabs"><?php print $tabs ?></div>
  55.         <?php if ($show_messages) { print $messages; } ?>
  56.         <?php print $help ?>
  57.         <?php print $content; ?>
  58.         <?php print $feed_icons; ?>
  59.       </div>
  60.     </td>
  61.     <?php if ($right) { ?><td id="sidebar-right">
  62.       <?php print $right ?>
  63.     </td><?php } ?>
  64.   </tr>
  65. </table>
  66.  
  67. <div id="footer">
  68.   <?php print $footer_message ?>
  69.   <?php print $footer ?>
  70. </div>
  71. <?php print $closure ?>
  72. </body>
  73. </html>
  74.  
  75.  
I have test_0512.php as a page that website should be resulted as clicking on Submit button.. but i don't know it seems like its not working. I don't know how to do this..Please help me out :(

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.  
  3. <head>
  4.  
  5. <title>TESTING PAGE</title>
  6. </head>
  7. <body>
  8. <?php
  9.  
  10.  
  11. $file = $_FILES['fileHandle']['name'];
  12.  
  13. move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],
  14.   "C:/upload/" . $_FILES["fileToUpload"]["name"]);
  15.  
  16.  if ($_FILES["fileToUpload"]["error"] > 0)
  17.     {
  18.     echo "Apologies, an error has occurred.";
  19.     echo "Error Code: " . $_FILES["fileToUpload"]["error"];
  20.     }
  21.  else
  22.     {
  23.  
  24.     move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],
  25.       "C:/upload/" . $_FILES["fileToUpload"]["name"]);
  26.     }
  27.  
  28.  
  29. //$file = fopen($fileName, "r") or exit ("Unable to open file!");
  30.  
  31. while(!feof($file))
  32. {
  33.  
  34.     $line = fgets($file); // Read a line.
  35.  
  36.  
  37. //escape if the line is empty
  38.         if (trim($line) == "")
  39.             continue;
  40. //explode from the :
  41.         $fields = explode(":", $line, 2);
  42.  
  43.         echo "<b>$fields[0]</b>";
  44.  
  45. //checks if second part exists 
  46.         if (isset($fields[1]))
  47.             echo " : $fields[1]";
  48.  
  49.         echo "<br/>";
  50.  
  51. }
  52.  
  53.     fclose($file);
  54. ?>
  55.  
  56. </body>
  57. </html>
  58.  
  59.  
May 21 '10 #1
1 2747
Niheel
2,460 Expert Mod 2GB
You should have the submission processing code in the same file as where you displayed the file. That way you can display the output in the same theme/layout.

To make sure that the processing only happens when a file is uploaded and the submit button is pressed, you'll have to do an if/else statement on the that page

Expand|Select|Wrap|Line Numbers
  1. if(isset($_POST['submit'])) { 
  2.   //add your file processing code here 
  3.  
  4.  
  5. }else{
  6.   // add your upload form here
  7.  
  8.  
  9. }
  10.  
May 21 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Drew | last post by:
I have a db table like the following, UID, int auto-increment RegNo Person Relation YearsKnown Now here is some sample data from this table,
2
by: nek | last post by:
Seasons greetings, Platform is W2K SP4, DB2 V8.1 FP2. A few days ago I posted the question to globally 'update db cfg' for all servers which could be done via a script thanks to Ian and PM's...
12
by: facicad | last post by:
Look my prog. I have combobox where is have all tables names of access file. The user select one table and the content is show in datagrid. The user can add, erase or modify some record or row. ...
2
by: Subhashini | last post by:
Hi friends, i have one doubt, that how can we update a file without using a temporary file in C. i need to do it in my program. If there is any way to do so then please let me know the procedure....
0
by: Learning.Net | last post by:
I have a window application that uses ActiveX browser component for testing web site automatically using mshtml. Though application is running fine but there is abnormally high page file usage....
6
by: Sunfire | last post by:
Is there a way you can test what page is loaded from inside a master page? What I need to do is test to see what page is loaded inside the master page and then gray out the root item linked to that...
0
by: George2 | last post by:
Hello everyone, I am not sure whether I am wrong or the Windows Internals Book 4th version is wrong. Here is what the book says in Chapter 7, Memory Management from Page 444 to Page 445 ...
0
by: =?Utf-8?B?TWF0dA==?= | last post by:
Hello, Can someone please advise. I have been unable to install any security, wmp and explorer updates for some time. Looking at the logs there seems to be trouble with the location of the...
0
by: Mike | last post by:
Is it possible to create an XML file to read from using a dropdown and based on the selection read the XML file again to populate some labels? Also, is it possible to update an XML file based on...
5
by: cfps.Christian | last post by:
Is there a way to tell a process to specifically use the page file for object storage? Our problem is we are loading objects that need to be stored during application runtime but not actually...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.