Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

save file to virtual directory

Hi I am unsure how to do this, I am using shared hosting. I have a virtual directory at http://www.example.com/images. This directory is actually a folder on the server assets/images whereas my site is at /httpdocs (httpdocs and assets folder are at the same level).

How can I save files to this folder and then access using eg /images/foo.jpg?

httpdocs/
--web.config
--default.aspx
--etc

assets/
--images/
----foo.jpg

like image 598
raklos Avatar asked Dec 22 '22 16:12

raklos


2 Answers

You can save files normally (using FileStreams or other things).
Call Server.MapPath("~/httpdocs") to get the path on disk.

like image 200
SLaks Avatar answered Jan 06 '23 20:01

SLaks


The simplest way is to create a virtual directory in the IIS Manager so that /images actually points to assets\images (you said you already have a virtual directory on it, so this may already be done). To save things there, you use Server.MapPath("~/images") as SLaks mentioned. Server.MapPath gives you the physical location and you can save to it the way you'd save a file normally.

Exactly how you save it depends on how the person is uploading it. Are you using a form where someone picks a file and then submits it on a web page? If you are, this link will help you with the saving part.

Good luck. :)

like image 41
Tridus Avatar answered Jan 06 '23 18:01

Tridus