www.webdeveloper.com
Results 1 to 5 of 5

Thread: File upload

  1. #1
    Join Date
    Mar 2013
    Posts
    4

    File upload

    Would someone be able to tell the easiest way to upload an image file to a server?

    I have a form created with HTML and javascript with some text boxes and a file input type for uploading a file. When i click the submit button it sends the data to an aspx file which adds it to a database on the server. The filename for the image is stored in the database, but i also want to upload the image to a file on the server. How would i go about that?

  2. #2
    Join Date
    Feb 2013
    Posts
    46
    That sounds like an asp.net question, not JavaScript.

  3. #3
    Join Date
    Mar 2013
    Posts
    4
    Well since the button to choose the file is located in the javascript code and since javascript lists the path as C:\fakepath\filename it kind of poses a problem for passing the upload to an aspx file even if i knew how to do it...

  4. #4
    Join Date
    Feb 2013
    Posts
    46
    Are you using AJAX to upload the file, or a regular form that submits to an ASP page?
    If AJAX:
    There is a ninja technique in order to do this, it is not intuitive. I won't get into it unless necessary.

    If form:
    The "action" attribute tells the form where to upload the file to. The "enctype" attribute can be used to upload a file by putting "multipart/form-data" as the value. Example:
    Code:
    <form method="post" action="/path/to/file.aspx" enctype="multipart/form-data">
    <input type="file" name="file">
    <button>Upload</button>
    </form>
    Change "/path/to/file.aspx" to your asp program that uploads files. You can put other data in this form, too- not just files. I don't know how to actually write the ASP code for uploading but I'm sure googling "ASP.net upload file" will tell you everything you need, including repeating what I just said about the form.

  5. #5
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    files are not a post param, they are in a different collection.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles