0

I keep on having "ACCESS DENIED" after hitting my download button. I already have full control on the specified folder.

I use this in 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+ ".");
    }
}
Daedalus
  • 7,586
  • 5
  • 36
  • 61
SyntaxError
  • 3,717
  • 6
  • 30
  • 31

1 Answers1

3

You can't access local files like you do in your snippet.

You have to upload the file to the server and use PHP/another serverside language to do that. jQuery (or Javascript) only runs in the browser and does not have access to files outside it. Serverside web-languages only have access to files located on the server (or other servers using get_file_contents or cURL).

Your code looks like a C#/Java-source. They can access these local files.

OptimusCrime
  • 14,662
  • 13
  • 58
  • 96
  • You do have "access" to local files through the browser, just think of an upload form. – Simon Jul 13 '12 at 07:09
  • @Simon : Not like OP is trying to do. He is trying to check if a local files exists or not in a folder on his computer. As far as I know; that is impossible using javascript. – OptimusCrime Jul 13 '12 at 07:12
  • oh i see. maybe i'll just relocate this code to my controller instead. – SyntaxError Jul 13 '12 at 07:19
  • Yeah just wanted to say "a browser does not have access to files outside it" is not quite true ^^ – Simon Jul 13 '12 at 07:20