2012-07-13 83 views
0

點擊我的下載按鈕後,我繼續有「ACCESS DENIED」。 我已經完全控制了指定的文件夾。下載文件:ACCESS DENIED

我在jquery中使用它。

function DownloadFile(ProductNumber, File) 
{ 
    var windowSizeArray = ["width=400,height=400", 
          "width=500,height=600,scrollbars=yes"]; 

    File = "C:/Documents and Settings/My PC/My Documents/" + File; 
    if (File != "") 
    { 

     var windowName = "popUp"; 
     var windowSize = windowSizeArray[$(this).attr("rel")]; 

     var exist = isExists(File); 
     if (exist) 
     { 
      window.open(File, windowName, windowSize); 
     } 
     else 
     { 
      ShowAlertMessage("The file for Product no. <a href='" + File + "' target='blank'>" + ProductNumber+ "</a> does not exist."); 
     } 
    } 
    else 
    { 
     ShowAlertMessage("No PDF file for Product no: " + ProductNumber+ "."); 
    } 
} 
+0

jquery不是一種語言,它是一個JavaScript庫,因此這個問題也落在了javascript上。 – Daedalus 2012-07-13 07:08:47

回答

3

就像你在你的代碼片段做您不能訪問本地文件。

您必須將文件上傳到服務器,並使用PHP /其他服務器端語言來執行此操作。 jQuery(或Javascript)只能在瀏覽器中運行,並且無法訪問它之外的文件。 Serverside網頁語言只能訪問位於服務器上的文件(或使用get_file_contents或cURL的其他服務器)。

您的代碼看起來像一個C#/ Java源代碼。他們可以訪問這些本地文件。

+0

您確實有通過瀏覽器「訪問」本地文件,只需考慮上載表單即可。 – Simon 2012-07-13 07:09:30

+0

@Simon:不像OP想要做的。他正試圖檢查本地文件是否存在於他的計算機上的文件夾中。我所知道的;這是不可能的使用JavaScript。 – OptimusCrime 2012-07-13 07:12:29

+0

哦,我明白了。也許我只是將這些代碼重新定位到我的控制器上。 – SyntaxError 2012-07-13 07:19:19