Link to home
Start Free TrialLog in
Avatar of vable
vable

asked on

Access is Denied error when uploading a file

When developing this file-upload form, I did not run into this problem. I was able to upload files no problem. When I wanted to change the looks and feel of the input file section, I begain recieving this error. Here are the pieces that I am more concern about:

function fileButtonClick()
{
     document.fileupload.file.click();
     document.fileupload.fakefile.value = document.fileupload.file.value;
}

--in the HTML section--
<form name="fileupload" enctype="multipart/form-data" action="process.asp" method="post" id="fileupload">

<input class="inputReadOnlyFields" type="text" name="fakefile" id="fakefile" />
<span id="browseButton" class="textAsLinks" onclick="fileButtonClick()">Browse</span>
<input type="file" name="file" id="file" style="visibility:hidden" />

For debugging purposes, I put two types of submitting items:

<span id="submitButton" class="textAsLinks" onclick="document.fileupload.submit()">Submit</span>
<button type="submit">Submit</button>

</form>

These two react differently (that is why I'm bringing it up). The first one (text) return the access is denied error. The other (the button) just clears out the text in the file field, but does nothing to the fakefile text. If I hit the submit button again, right afterwards, the form is submitted but with no file.

If anyone could help, it would be greatly appreciated!

Chris
Avatar of Gary
Gary
Flag of Ireland image

The File tag has security properties e.g you can't set the value for obvious reasons, this is probably why you're getting an error and why it wont let you submit the value.   Otherwise any site I visit could pull files from my pc without my knowing
ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vable
vable

ASKER

I completely agree with your reasoning; however, the server is not assigning a string of a file, the client is. In other words, I when the user clicks on the browse link it activates the browse button of the input tag. Therefore, the input tag is retrieving a string from it (the browse button). I am not reassigning the value of the file tag otherwise I would expect a security error.
The browser must be seeing it as an attempt to hack the File tag and hence is not allowing it.
Avatar of vable

ASKER

Doing some more debuggin, I found out that the browser does not have a problem with the document.fileupload.fakefile.value = document.fileupload.file.value; piece but rather fact that I am executing the click function of the file tag from javascript. The browser probably thinks that I am "hacking" the user by doing this. If only I can find another way invoking that method.
Avatar of vable

ASKER

Researching this topic some more, I found out that the only way to have the file tag work properly is the user must click on the Browse button, and not any other way (e.g. using javascript to invoke the click method of the file tag). Also, I cannot format the style of how this tag look (at least not yet), which was my initial content. So, for the question I asked, there is no answer that anyone could give me that would work for this method of formatting or invoking the file tag. However, GaryC123 did give me some information that does explain why I am receiving the error that I have mention.

Thanks,
Chris
Well in my second comment I did say you have to use the File tag with its own Browse button.
Avatar of vable

ASKER

Yes, I realize that. That is why I accepted that comment as the answer.
Avatar of vable

ASKER

Lunchy,

If GaryC123 is complaining about my grade that I have awarded him, fine, I will change it. However, "askers" should have more than 3 options when it comes to grading. Perhaps a number scale of 1 to 100 would be more efficient. Perhaps the webmaster(s) should also put experts' average next to their names; this will tell other people valuable information such as:

What do other people think of this person?
Should I trust this person and spend time doing what he/she suggests?
When grading this person, what kind of grade should I give that will not negatively affect her/his current average?

The reason why I gave this grade was because I did not receive an answer that I was looking for. Perhaps the answer is not the easiest answer; however, to me, it would better than to just "deal with it"

Just send me to the right page to adjust the grade and I will.

Chris