Problem when uploading a file in form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • agarwalsrushti
    New Member
    • Feb 2008
    • 63

    Problem when uploading a file in form

    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.

    [code=php]
    <tr>
    <td bgcolor="#ECE9D 8"> <div align="center">
    <span class="style14" >
    <input type="hidden" name="MAX_FILE_ SIZE" value="8000000" >
    Select file: </span>
    <input type="file" name="data">
    <input type="submit" name="Submit" value="Upload File">
    </div>
    </td>
    </tr>
    <tr>
    <td height="38" bgcolor="#ECE9D 8"><div align="center">

    <input name="Reset" type="reset" id="Reset" value="Reset" />
    <input type="submit" name="Submit" value="Submit" />

    </div></td>
    </tr>
    </form>

    <?php
    } else {
    // check uploaded file size
    if ($_FILES['data']['size'] == 0) {
    die("ERROR: Zero byte file upload");
    }

    // check if file type is allowed (optional)
    $allowedFileTyp es = array("text/plain", "applicatio n/msword");
    if (!in_array($_FI LES['data']['type'], $allowedFileTyp es)) {
    die("ERROR: File type not permitted");
    }

    // check if this is a valid upload
    if (!is_uploaded_f ile($_FILES['data']['tmp_name'])) {
    die("ERROR: Not a valid file upload");
    }

    // set the name of the target directory
    $uploadDir = "./uploads/";

    // copy the uploaded file to the directory
    move_uploaded_f ile($_FILES['data']['tmp_name'], $uploadDir .$_FILES['data']['name']) or die("Cannot copy uploaded file");

    // display success message
    echo "File successfully uploaded. " ;
    }
    [/code]
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    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

    Comment

    • mageswar005
      New Member
      • Mar 2008
      • 72

      #3
      hi,
      i think your submit button name is submit, is it correct?
      please change your submit button name.
      Last edited by ronverdonk; Mar 14 '08, 02:32 PM. Reason: code not necessary for post

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        Originally posted by mageswar005
        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

        Comment

        • agarwalsrushti
          New Member
          • Feb 2008
          • 63

          #5
          Originally posted by ronverdonk
          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.

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            Originally posted by agarwalsrushti
            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.

            Comment

            • agarwalsrushti
              New Member
              • Feb 2008
              • 63

              #7
              Whats a hidden iframe and how to use it. Plz let me know im stuck up with this.

              Comment

              • Markus
                Recognized Expert Expert
                • Jun 2007
                • 6092

                #8
                Have a look at this
                :)

                Comment

                • ronverdonk
                  Recognized Expert Specialist
                  • Jul 2006
                  • 4259

                  #9
                  Originally posted by agarwalsrushti
                  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

                  Comment

                  • agarwalsrushti
                    New Member
                    • Feb 2008
                    • 63

                    #10
                    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.

                    Comment

                    • ronverdonk
                      Recognized Expert Specialist
                      • Jul 2006
                      • 4259

                      #11
                      Originally posted by agarwalsrushti
                      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

                      Comment

                      • agarwalsrushti
                        New Member
                        • Feb 2008
                        • 63

                        #12
                        Thanks the link realyy helped me a lot.
                        IMy problem got solved. Its uploading properly without submitting the data.
                        Thanks a lot.

                        Comment

                        Working...