473,749 Members | 2,464 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to upload file and submit button to other page (PHP)

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.  
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.     $line = fgets($file); // Read a line. 
  34.  
  35.  
  36. //escape if the line is empty 
  37.         if (trim($line) == "") 
  38.             continue; 
  39. //explode from the : 
  40.         $fields = explode(":", $line, 2); 
  41.  
  42.         echo "<b>$fields[0]</b>"; 
  43.  
  44. //checks if second part exists  
  45.         if (isset($fields[1])) 
  46.             echo " : $fields[1]"; 
  47.  
  48.         echo "<br/>"; 
  49.  
  50.  
  51.     fclose($file); 
  52. ?> 
  53.  
  54. </body> 
  55. </html> 
  56.  
  57.  
  58.  

Someone replied me that I should put below code but I could not get it..
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.  
May 24 '10 #1
2 9436
dlite922
1,584 Recognized Expert Top Contributor
I'm not familiar with Drupal, but the code suggested means that if anything is submitted (in $_POST['submit']), then do this, else display the original page (whatever the page is before the user clicks submit)

I'm worried that if you don't understand that piece of code, how you will have the level of PHP programming skills to do what you need to do.

I would go back to some PHP tutorials and learn the language more if you want to do this yourself

Good luck,



Dan
May 25 '10 #2
lka527
15 New Member
@dlite922
actually I understood that part I just did not know how to implement that...
I meant, I plugged this recommended code into the page where the replier mentioned me to do but that was messing me up with other codes..
May 25 '10 #3

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

Similar topics

2
3821
by: anonieko | last post by:
Scenario: You have a page that is TOO slow to refresh. But it allows partial flushing of html contents. I.e. Submit button already appears but you don't want your users to click on it prematurely because other parts are still coming. Here I put a javascript the will enable only submit button only after 5 seconds after the page is load fully.
2
1438
by: Brian | last post by:
Hi, I've been trying to find a way to upload file to another site that is not using IIS. The site that I want to upload file to has a simple php script to receive file uploaded through standard http post with a file upload. However, how do I upload file to the site using asp.net? thanks Brian
3
2431
by: Brian | last post by:
Hi, I've been trying to find a way to upload file to another site that is not using IIS. The site that I want to upload file to has a simple php script to receive file uploaded through standard http post with a file upload. However, how do I upload file to the site using asp.net? thanks Brian
1
2715
by: Ibrahim. | last post by:
Hi, I have a login page, the problem I'm facing is like this; 1. Login page with submit button (being default button); 2. When first time the page is submitted then submit code is called. 3. Again when page refresh is done by (f5) then submit button is fired implicitly.
2
4319
by: todanrg3 | last post by:
It is possible to upload files to Rapidshare from another page?(not using Rapidshare's own form). How can i do this with PHP?
3
3806
by: ChrisN | last post by:
Invoking a postback before a large ASP.NET page has fully rendered will often cause the page to crash. This is unhelpful and confusing to users. I'm wondering if I can overcome this by disabling any controls that invoke a postback until the page is fully rendered, ie setting the controls disabled server-side, serving the page and then having a JavaScript routine right at the bottom of the page re-enable them client-side.
3
2723
by: pratibharaut | last post by:
i'm not able to upload file from mobile J2ME to php 5.2.2, plz help me for that, same code is running in php4.3, but not in php5.2.2. I'm using $_FILES for uploading file, while using print_r($_FILES), it showname,type and error=3 and size=0 why this is happened? plz help me .
2
5970
by: Bjorn Sagbakken | last post by:
I was looking for a solution, without the full page postback, and all the tip was about a hidden iframe and RJS. The RJS was not known to me before, and still I haven't explored this used with ASP.NET But, the iframe issue gave me an idea; why not put the fileupload control & a submit button on a form, nothing else. Then on my main form I added an iframe, a visible one, with src=the form with the file upload control. Ok, this shows...
6
2744
by: obj63 | last post by:
Hello All, I am posting to a page with out a submit button using the function sendToHost - http://dodds.net/~cardinal/sendtohost.txt I send the following sendToHost('www.example.com','post','/page.php', 'ERROR=01'); where www.example.com is my site. The problem then is that page.php on the site should then read from the $_POST variable and write out the Error to the file.
7
15858
by: ChristinaTIT | last post by:
Hi, I have a form containing ID Type Quantity Rate values. it should have two submit buttons which, when posted, will do the two different things in two different scripts.
0
8996
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8832
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9562
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9386
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9333
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
6078
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.