Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Uploading images to web server

Reply
Thread Tools

Uploading images to web server

 
 
=?Utf-8?B?R2F2aW4=?=
Guest
Posts: n/a
 
      01-22-2006
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

 
Reply With Quote
 
 
 
 
Kevin Spencer
Guest
Posts: n/a
 
      01-23-2006
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" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
>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
>



 
Reply With Quote
 
 
 
 
Zeeshan Muhammad
Guest
Posts: n/a
 
      01-23-2006
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" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
>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
>



 
Reply With Quote
 
Patrick.O.Ige
Guest
Posts: n/a
 
      01-23-2006
Gavin you can just re write your code in ASP.NET
It will make life easier for you.
Patrick


"Gavin" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

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 Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Uploading Images/Files To Server rn5a@rediffmail.com ASP General 1 06-06-2007 01:39 AM
Uploading Images/Files To Server rn5a@rediffmail.com ASP .Net 1 06-06-2007 12:05 AM
Uploading images files to server and resize the image =?Utf-8?B?am9l?= ASP .Net 1 07-21-2006 09:27 AM
ftp uploading vs. control panel uploading Dung Ping HTML 10 01-16-2006 10:43 AM
uploading FOLDERS of images via .net darrel ASP .Net 3 07-23-2004 10:11 PM



Advertisments