FileUpload from Subdomain to Folder of Main Domain

梦想与她 提交于 2019-12-12 10:17:08

问题


I tried ridiculous searches and don't really know what to search.

I'm less than a novice in programming (graphic designer that knows too much), is it possible to have a subdomain website upload files to the parent website.

The current code is:

if (FileUpload1.HasFile)
  {
    string webPath = "~/Uploads/Files/";

I have tried:

if (FileUpload1.HasFile)
  {
    string webPath = "http://domain.com/Uploads/Files/";

Any help and direction would be appreciated, thanks!

Update 01

I've also tried:

if (FileUpload1.HasFile)
  {
    string webPath = "../../httpdocs/Uploads/Files/";

which gave the following error: Cannot use a leading .. to exit above the top directory.

Update 02

After some more googling I suspected that I'm calling some path twice. So I got this to work, but I'm not entirely sure how secure it is.

if (FileUpload1.HasFile)
  {
    string sysPath = "C:/Inetpub/vhosts/domain.com/httpdocs/Uploads/Files/";

Then for downloading again, there's a separate file Download.aspx where I had to change the code as follows

response.TransmitFile("C:/Inetpub/vhosts/domain.com/httpdocs/Uploads/Files/" + filename);

回答1:


it's normally .. to go up a level so ../ would go up one level, easy way to get the path is to drag something from a folder into the ide in source code mode and it will create a link with the correct path and ditch the HTTP, your not loading a resource like you would an image, your just saying use this folder path




回答2:


Thanks to @MikeH I came to a solution. In short for uploading...

// USE TO SAVE TO SERVER C:
string sysPath = "C:/Uploads/ClientFiles/";

and for downloading...

// USE TO DOWNLOAD FROM SERVER C:
Response.TransmitFile(@"C:/Uploads/ClientFiles/" + filename);

Don't forget to set the folder permissions as well. Please see the solution on my security question How Secure is string sysPath = "C:/Inetpub/vhosts/..."




回答3:


I have done it this way:

string ThisDir = "E:/AjkerDealLatest/images/Deals";
System.IO.Directory.CreateDirectory(ThisDir + "\\" + FolderNameHiddenField.Value);
ImageName = Request.Form.GetValues("name");
string path = Path.Combine("E:/AjkerDealLatest/images/Deals/"+ FolderNameHiddenField.Value, ImageName[0] + ".jpg");

file.SaveAs(path);


来源:https://stackoverflow.com/questions/22536660/fileupload-from-subdomain-to-folder-of-main-domain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!