473,508 Members | 4,628 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem when uploading a file in form

63 New Member
Hi,
Ive created a registration page in which at the last it asks the user to upload the resume file. When the user clicks on the upload button to upload the file it automativcally submits all the data entered in the form. I want that when the user uploads the file after clicking the upload button it should display the message of successful upload on the same page itself. Then when the user clicks on the submit button the data should be entered in the database.
Ive attached the registration form file plz let me know how i can fix this problem.
I ve given the required code below.

Expand|Select|Wrap|Line Numbers
  1. <tr>
  2.     <td bgcolor="#ECE9D8"> <div align="center">
  3.       <span class="style14">
  4.       <input type="hidden" name="MAX_FILE_SIZE" value="8000000">
  5.        Select file: </span>
  6. <input type="file" name="data">
  7. <input type="submit" name="Submit" value="Upload File">
  8. </div>
  9.       </td>
  10.   </tr>
  11.   <tr>
  12.     <td height="38" bgcolor="#ECE9D8"><div align="center">
  13.  
  14.       <input name="Reset" type="reset" id="Reset" value="Reset" />
  15.       <input type="submit" name="Submit" value="Submit" />
  16.  
  17.     </div></td>
  18.   </tr>
  19.   </form>
  20.  
  21.  <?php
  22. } else {
  23. // check uploaded file size
  24. if ($_FILES['data']['size'] == 0) {
  25. die("ERROR: Zero byte file upload");
  26. }
  27.  
  28. // check if file type is allowed (optional)
  29. $allowedFileTypes = array("text/plain", "application/msword");
  30. if (!in_array($_FILES['data']['type'], $allowedFileTypes)) {
  31. die("ERROR: File type not permitted");
  32. }
  33.  
  34. // check if this is a valid upload
  35. if (!is_uploaded_file($_FILES['data']['tmp_name'])) {
  36. die("ERROR: Not a valid file upload");
  37. }
  38.  
  39. // set the name of the target directory
  40. $uploadDir = "./uploads/";
  41.  
  42. // copy the uploaded file to the directory
  43. move_uploaded_file($_FILES['data']['tmp_name'], $uploadDir .$_FILES['data']['name']) or die("Cannot copy uploaded file");
  44.  
  45. // display success message
  46. echo "File successfully uploaded. " ;
  47. }
  48.  
Mar 14 '08 #1
11 1984
ronverdonk
4,258 Recognized Expert Specialist
Do you mean that the user has to click twice? Once for the upload and once for the passing of the form variables. Then you better make sure that you also have 2 forms.

Ronald
Mar 14 '08 #2
mageswar005
72 New Member
hi,
i think your submit button name is submit, is it correct?
please change your submit button name.
Mar 14 '08 #3
ronverdonk
4,258 Recognized Expert Specialist
hi,
i think your submit button name is submit, is it correct?
please change your submit button name.
Why do you care what the submit button name is when you don't test the $_POST['submit'] parm?

Another thing is that you have 2 type=submit buttons so, whichever you click, the form will be submitted despite the text on the button (submit or upload).

Ronald
Mar 14 '08 #4
agarwalsrushti
63 New Member
Why do you care what the submit button name is when you don't test the $_POST['submit'] parm?

Another thing is that you have 2 type=submit buttons so, whichever you click, the form will be submitted despite the text on the button (submit or upload).

Ronald
Yes i know the problem is because of 2 type=submit buttons. Is there any way by which this problem can be solved. On normal job sites when you upload the file it doesnt submits the dat.
Mar 14 '08 #5
Markus
6,050 Recognized Expert Expert
Yes i know the problem is because of 2 type=submit buttons. Is there any way by which this problem can be solved. On normal job sites when you upload the file it doesnt submits the dat.
Why do you need 2 submit buttons in the first place?

You're talking about uploading an image without refreshing the page.
You'll need to use a hiden iframe for that.

Can't say much more as im ill!

markusn00b ------------------> going to bed.
Mar 14 '08 #6
agarwalsrushti
63 New Member
Whats a hidden iframe and how to use it. Plz let me know im stuck up with this.
Mar 14 '08 #7
Markus
6,050 Recognized Expert Expert
Have a look at this
:)
Mar 14 '08 #8
ronverdonk
4,258 Recognized Expert Specialist
Yes i know the problem is because of 2 type=submit buttons. Is there any way by which this problem can be solved. On normal job sites when you upload the file it doesnt submits the dat.
A submit button submits the form in which it is included. So when you use 2 of those, you make 2 forms, each with its own submit/upload button.

And when you don't know what an iframe is, I suggest that you follow Mark's advice and do some toturialing on HTML and PHP.

Ronald
Mar 14 '08 #9
agarwalsrushti
63 New Member
Thanks.
Iwill study the link you gave and if any problem persists i ll let u know. Its a very good link that you suggested.
Mar 16 '08 #10
ronverdonk
4,258 Recognized Expert Specialist
Thanks.
Iwill study the link you gave and if any problem persists i ll let u know. Its a very good link that you suggested.
I hope you succeed. See you around.

Ronald
Mar 16 '08 #11
agarwalsrushti
63 New Member
Thanks the link realyy helped me a lot.
IMy problem got solved. Its uploading properly without submitting the data.
Thanks a lot.
Mar 20 '08 #12

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

Similar topics

2
2440
by: Tim | last post by:
I meet problem on uploading a file with a large file size. Below is my code, how can I modify in order to be able to upload a large file successfully ? Thank for your help. upload.html: <html>...
3
2178
by: Mike Walsh | last post by:
I have a problem uploading files with PHP which has me stumped! I am unable to successfully upload files. My simple test script is as follows: <?php if (count($_FILES)) { var_dump($_FILES)...
1
2190
by: Jonathan | last post by:
Hi everyone, I have a problem with the file uploading in Asp.Net and I have read a lot on forums on this but never found an answer. Here is the problem: I know Asp.Net maximum Length for...
4
14475
by: R Reyes | last post by:
I am trying to code a file uploader (for forum/email attachments) from the client computer to a remote web server via the PUT method (since POST is not allowed ). However, the upload works ONLY...
2
5920
by: prakharv | last post by:
Hi All, Below is the code which I am using to upload a jpeg file to the server. But the problem I am facing is that it is not copying the entire contents of the image file to the webserver and it...
3
3890
by: dreamznatcher | last post by:
Hello, I found a script here: http://www.webtoolkit.info/ajax-file-upload.html which supposedly allows you to upload files using AJAX (I'm not an expert). The site claims it's the best way to...
3
1900
ganesanji
by: ganesanji | last post by:
hi all, I have written a php coding for uploading a file to a specific folder or location in server which is a Linux server. I think the coding for file uploaing is correct. But it does not...
3
3993
by: kujtim | last post by:
i got html code file name html <html> <head> <title></title> </head> <body>
1
2105
pezholio
by: pezholio | last post by:
Hi, It seems that every time I put together a new script to upload a file I always have problems, here's the latest one: I've got a form with two file input fields, when I submit the form,...
1
4387
Canabeez
by: Canabeez | last post by:
Hi all, anyone has an idea why IE is not uploading file and FF does? I'm creating a FORM + IFRAME using DOM and trying to upload a file, now Firefox and Chrome do thins perfectly. I have...
0
7128
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...
0
7332
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,...
0
7393
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...
1
7058
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...
0
7502
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...
0
3206
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...
0
3191
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1565
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 ...
0
426
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...

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.