If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Uploading an image to a folder on the server

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-26-09, 12:45
ianj846 ianj846 is offline
Registered User
 
Join Date: Feb 2009
Posts: 10
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
Reply With Quote
  #2 (permalink)  
Old 05-27-09, 01:31
Ax238 Ax238 is offline
Registered User
 
Join Date: May 2009
Posts: 253
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.
Reply With Quote
  #3 (permalink)  
Old 05-27-09, 06:52
ianj846 ianj846 is offline
Registered User
 
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
Reply With Quote
  #4 (permalink)  
Old 05-27-09, 11:20
Ax238 Ax238 is offline
Registered User
 
Join Date: May 2009
Posts: 253
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
Reply With Quote
  #5 (permalink)  
Old 05-27-09, 12:41
ianj846 ianj846 is offline
Registered User
 
Join Date: Feb 2009
Posts: 10
Smile

Thanks very much.

I will give it a go

Ian
Reply With Quote
  #6 (permalink)  
Old 05-28-09, 00:28
Ax238 Ax238 is offline
Registered User
 
Join Date: May 2009
Posts: 253
You're welcome, let me know if that does it.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On