473,569 Members | 3,054 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to update page after a file is uploaded?

15 New Member
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 2754
Niheel
2,456 Recognized Expert Moderator Top Contributor
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
4068
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
1458
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 responses. I would like to do the same to a file containing plain text that exists on ALL W2K servers which are of identical h/w configuration.
12
1974
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. Until now is ok but went I want to update access file, VB send me error. Some body can help me Dim myCnn As New OleDb.OleDbConnection Dim...
2
1848
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. Thanks N regards Subu
0
2080
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. The Maximum PF Usage often rising as high as 2 GB. How to reduce this page file usage & reasons behind this high page file usage? Anyone can help...
6
3845
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 page in the Menu control. I.e. I have a root item called home. When a person is on the home page I want it to be disabled. Any way to do this?
0
2366
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
1300
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 update.inf file and this seems to tie in with other peoples problems on the newsgroup. However, on performing a file search to find the location of...
0
1206
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 the user selection? example: my xml file looks like this <Cars>
5
2517
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 saved until told to do so. In our case these objects can easily eat 300+ MB of memory. Unfortunately we can't save any of the images until the...
0
7619
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7681
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5228
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
950
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.