Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2009
    Posts
    10

    Unanswered: Uploading an image to a folder on the server

    Hi All,

    I am trying to upload an image using an admin area on my site.

    I use CuteFTP to upload all my files but the in the admin area this is not possible, as it will be quite a few people using it.

    I would like to browse to an image folder, select an image, then press the submit button and it uploads it to the images folder on the server.

    I have used the following code to select the file,

    Response.Write("<input type=FILE size=60 name=FileUpload><br><br>")
    Response.Write("<input type=submit name=submit value=""Upload"">")

    I am struggling to get the code so that when the submit button is clicked it upoads the image.

    Any help would be greatly appreciated.


    Ian

  2. #2
    Join Date
    May 2009
    Posts
    258
    Hi Ian,

    You'll have to make sure you specify
    content-type="multipart/form-data"

    on the form element. You'll then be able to use the Request.Files object to work with the files.

  3. #3
    Join Date
    Feb 2009
    Posts
    10
    Hi,

    Thanks for getting back to me.

    Can you explain, "the Request.Files object to work with the files."

    I am not sure what the code would be for this, or where it would go.

    Thanks

    Ian

  4. #4
    Join Date
    May 2009
    Posts
    258
    Sorry about that, it was late when I responded and my mind was on .NET. There is no Request.Files object in ASP, you have to parse the bytes. There's a pretty good sample located at the following link:
    Pure ASP File Upload

    If your site is on a hosting server, you may not know the exact directory in which to store the file, so you can use Server.MapPath and Scripting.FileSystemObject to get it where you want it. The following might help on that:
    Uploading Files to the Server Hard Disk using plain ASP

    Also, in ASP pages, you can mix regular HTML with VBScript, rather than having to do a Response.Write on the HTML elements. For example:
    Code:
    <% If Session("UserType") = "Admin" Then %>
    <input type="file" size="60" name="FileUpload" /><br /><br />
    <input type="submit" name="submit" value="Upload" />
    <% End If %>
    Regards,

    Ax

  5. #5
    Join Date
    Feb 2009
    Posts
    10

    Smile

    Thanks very much.

    I will give it a go

    Ian

  6. #6
    Join Date
    May 2009
    Posts
    258
    You're welcome, let me know if that does it.

Posting Permissions

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