Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Dec 2003
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Custom upload form

    Hi everyone!

    I've got a question. Is it possible to build a custom file upload form, and if it is, then how? For example, the form I am building will not be used for English-speaking users, so, I would the "Browse" button to be in the customer's language, but, they are using English OSs. Then, I don't any field at all and I want to control what format (like to reduce to images only) of files can be uploaded. I know that there are some security resctrictions onto file upload fields, but still I would like to know for sure if there is no other way of doing that. Also, is it possible to a file through a POST request using JS?

    THanks a lot to everyBUDDY!

  • #2
    Regular Coder
    Join Date
    Apr 2003
    Location
    Atlanta, GA
    Posts
    487
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Theoretically, you can have a text input next a button, and a hidden file input tied to the button's onclick event:
    Code:
    <form>
    <input type="text" id="fakeFileName" name="fakeFileName" />
    <input type="button" value="Click me to upload!" onclick="this.form.fileField.click();" />
    <input type="file" id="fileField" name="fileField" onchange="this.form.fakeFileName.value=this.value;" />
    </form>
    ...but that's untested, and probably unsupported in most browsers.

    To limit what's accepted, you can filter by mime-type by using the "accept" attribute:
    Code:
    <input type="file" accept="image/*,text/plain-text,application/x-pdf" />
    This will let you accept any image, plain-text file, or PDF document that the client wishes to upload. For more on mime-types, visit your local friendly search engine.

    A post request cannot be faked (which would equal being constructed completely in javascript), but a form post can be triggered with the form.submit() method.
    Code:
    <form name="myform">...</form>
    <a href="document.forms['myform'].submit()">Submit the form!</a>
    Note: this bypasses the form.onsubmit event and its handler(s), so beware. If client-side validation is important, make sure to add that into your script before your submit() method call.


    Good questions.

  • #3
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    You need a serverside language to upload files. Then just use that language to check which file type is being uploaded.

  • #4
    New Coder
    Join Date
    Dec 2003
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I gotcha. Can you recommend a good language, on which you could do what I am saying. For example, my customers is uploading a huge file and then at the end he finds out that it's not allowed to download this kind of files, only after he uploaded it, then he calls me and tells me that they don't want to work with me anymore.

    I want to make client-side check w/o uploading the file itself.

    Thanks guys. I really need a solution for this.

  • #5
    Senior Coder
    Join Date
    Aug 2002
    Location
    Kansas City, Kansas
    Posts
    1,518
    Thanks
    0
    Thanked 2 Times in 2 Posts
    I think you can do this with php...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •