473,396 Members | 2,158 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Uploading images to web server

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
3 2281
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: laredotornado | last post by:
Hi, I'm using PHP 4 and I am submitting some images in a form with <form name=addProductForm enctype="multipart/form-data" method=post action="add_product_response.php"> <input type=file...
2
by: Paul Gorman | last post by:
I am using the control type = file to perform a file upload. When I click on the browse button to go select the image I want to upload it places in the text box a local path (C:\images\image.jpg...
5
by: Grant Harmeyer | last post by:
I have an application that uses FreeTextBox 2.0 (http://www.freetextbox.com). FreeTextBox is a rich text editor that behaves similarly to MS Word. The FreeTextBox control has a button to insert...
4
by: Ramakrishnan Nagarajan | last post by:
Hi, I am facing a different problem in my application. In that I am uploading a folder that contain only images. Everything was done and was working fine too. When I executed the application using...
1
by: joe | last post by:
Any articles relating with Uploading images files to server and resize the image by asp.net 2.0
1
by: Nerry | last post by:
Hello everyone, I have ASP webpages, but I have a problem uploading my images via ftp, keep getting an error: An error occurred copying a file to the ftp server. Make sure you have permissions...
14
w33nie
by: w33nie | last post by:
What I'm trying to do here, is upload a video to the ../video/ folder, and up to 5 images to the ../images/ folder. As well as the database information like title, content and each file's file...
2
by: lavadan | last post by:
Hi Folks, I am a newbie to SQL Server. Please help me with this. I have some tiff files. I have to upload them into sql server. How do i do this. I will be getting the tiff files in a hardware...
7
by: nwclark | last post by:
Ok... I have a noobie issue. I am trying to upload a photo to specific directory on my server. (this is working correctly with the code below). However, I am also trying to rename the file and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.