Uploading images to web server

Discussion in 'ASP .Net' started by =?Utf-8?B?R2F2aW4=?=, Jan 22, 2006.

  1. 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
     
    =?Utf-8?B?R2F2aW4=?=, Jan 22, 2006
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:D...
    >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
    >
     
    Kevin Spencer, Jan 23, 2006
    #2
    1. Advertising

  3. 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.FileName);
    // 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,fileUpload.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" <> wrote in message
    news:D...
    >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
    >
     
    Zeeshan Muhammad, Jan 23, 2006
    #3
  4. Gavin you can just re write your code in ASP.NET
    It will make life easier for you.
    Patrick


    "Gavin" <> wrote in message
    news:D...
    > 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
    >
     
    Patrick.O.Ige, Jan 23, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. darrel
    Replies:
    3
    Views:
    2,355
    Steve C. Orr [MVP, MCSD]
    Jul 23, 2004
  2. Dung Ping
    Replies:
    10
    Views:
    1,061
    Chaddy2222
    Jan 16, 2006
  3. =?Utf-8?B?am9l?=
    Replies:
    1
    Views:
    393
    =?Utf-8?B?TXVyYWxp?=
    Jul 21, 2006
  4. Replies:
    1
    Views:
    296
    Steve C. Orr [MCSD, MVP, CSM, ASP Insider]
    Jun 6, 2007
  5. Replies:
    1
    Views:
    132
    Bob Barrows [MVP]
    Jun 6, 2007
Loading...

Share This Page