By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,383 Members | 2,070 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,383 IT Pros & Developers. It's quick & easy.

Uploading images to web server

P: n/a
I need some help, I need the code to allow people that visit my website to be
able to upload pictures to a file on my web server. I have been able to get
close, but not quite there yet.

Set fso = createobject("scripting.filesystemobject")
Set act = fso.CreateTextFile(server.mappath("test.jpg"), true)
act.WriteLine
act.Close

The above code will create the file but will not write any data in it. Below
is the htm code that lets the user upload the file.

<form method="post" action="" name="submit" enctype="multipart/form-data">
Choose A File: <input type="file" name="filefield"><br><br>
<input type="submit" name="submit" value="submit"><br>
</form>
The problem is I can't get the upload image file information to pass
between the htm page to the asp page in a form that it can be written to a
file. I am also not sure that I am using the correct asp code since it is not
a text file I am trying to write. But it is the only code I can find. I do
not need to check to see if the file exits or anything else. All I need is to
upload an image from the htm page pass it to the asp page in the correct form
to be written then write it directly to my web server.

Thanks for you help

Jan 22 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Try posting to the ASP newsgroup: microsoft.public.inetserver.asp.general.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Who is Mighty Abbott?
A twin turret scalawag.

"Gavin" <Ga***@discussions.microsoft.com> wrote in message
news:D9**********************************@microsof t.com...
I need some help, I need the code to allow people that visit my website to
be
able to upload pictures to a file on my web server. I have been able to
get
close, but not quite there yet.

Set fso = createobject("scripting.filesystemobject")
Set act = fso.CreateTextFile(server.mappath("test.jpg"), true)
act.WriteLine
act.Close

The above code will create the file but will not write any data in it.
Below
is the htm code that lets the user upload the file.

<form method="post" action="" name="submit" enctype="multipart/form-data">
Choose A File: <input type="file" name="filefield"><br><br>
<input type="submit" name="submit" value="submit"><br>
</form>
The problem is I can't get the upload image file information to pass
between the htm page to the asp page in a form that it can be written to a
file. I am also not sure that I am using the correct asp code since it is
not
a text file I am trying to write. But it is the only code I can find. I do
not need to check to see if the file exits or anything else. All I need is
to
upload an image from the htm page pass it to the asp page in the correct
form
to be written then write it directly to my web server.

Thanks for you help

Jan 23 '06 #2

P: n/a
Uploading images is a very easy procedure. You don't actually have to make a
file and write the contents on it. Rather you can just save the image your
user wants to upload. Here's the piece of code that will do the work for
you:

// The path where you want to store the images
string Path = Server.MapPath("images/");
// Filename of the image from fileupload html control with id "fileUpload"
string FileName =
System.IO.Path.GetFileName(fileUpload.PostedFile.F ileName);
// Create a byte array to read contents of the file
byte[] Data = new Byte[fileUpload.PostedFile.ContentLength];
// Read the contents of the file into a stream
fileUpload.PostedFile.InputStream.Read(myData,0,fi leUpload.PostedFile.ContentLength);
// Save the stream to server
FileStream Stream = new FileStream(Path + FileName, FileMode.Create);
Stream.Write(Data,0, myData.Length);
Stream.Close();

Aboe code is in C#, you can convert it into VB.NET as per your requirement.
I hope it will be helpful.

Zeeshan.
http://zishu.blogspot.com
"Gavin" <Ga***@discussions.microsoft.com> wrote in message
news:D9**********************************@microsof t.com...
I need some help, I need the code to allow people that visit my website to
be
able to upload pictures to a file on my web server. I have been able to
get
close, but not quite there yet.

Set fso = createobject("scripting.filesystemobject")
Set act = fso.CreateTextFile(server.mappath("test.jpg"), true)
act.WriteLine
act.Close

The above code will create the file but will not write any data in it.
Below
is the htm code that lets the user upload the file.

<form method="post" action="" name="submit" enctype="multipart/form-data">
Choose A File: <input type="file" name="filefield"><br><br>
<input type="submit" name="submit" value="submit"><br>
</form>
The problem is I can't get the upload image file information to pass
between the htm page to the asp page in a form that it can be written to a
file. I am also not sure that I am using the correct asp code since it is
not
a text file I am trying to write. But it is the only code I can find. I do
not need to check to see if the file exits or anything else. All I need is
to
upload an image from the htm page pass it to the asp page in the correct
form
to be written then write it directly to my web server.

Thanks for you help

Jan 23 '06 #3

P: n/a
Gavin you can just re write your code in ASP.NET
It will make life easier for you.
Patrick
"Gavin" <Ga***@discussions.microsoft.com> wrote in message
news:D9**********************************@microsof t.com...
I need some help, I need the code to allow people that visit my website to be able to upload pictures to a file on my web server. I have been able to get close, but not quite there yet.

Set fso = createobject("scripting.filesystemobject")
Set act = fso.CreateTextFile(server.mappath("test.jpg"), true)
act.WriteLine
act.Close

The above code will create the file but will not write any data in it. Below is the htm code that lets the user upload the file.

<form method="post" action="" name="submit" enctype="multipart/form-data">
Choose A File: <input type="file" name="filefield"><br><br>
<input type="submit" name="submit" value="submit"><br>
</form>
The problem is I can't get the upload image file information to pass
between the htm page to the asp page in a form that it can be written to a
file. I am also not sure that I am using the correct asp code since it is not a text file I am trying to write. But it is the only code I can find. I do
not need to check to see if the file exits or anything else. All I need is to upload an image from the htm page pass it to the asp page in the correct form to be written then write it directly to my web server.

Thanks for you help

Jan 23 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.