Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2003
    Location
    AR
    Posts
    2,382

    Upload field - Default Folder

    I think I know what the answer is to this, but I need to double check. My client is the author of a desktop application for school systems. This program generates a file that needs to be uploaded and parsed on his website. The problem is that some school administrators are not technically savvy people, and end up uploading the wrong files - Often times backup files that they have stored in their Documents or Desktop.

    Is there ANY way (Java Applet, Flash, JavaScript, or plain HTML) to default a File upload box to a certain folder? The generated file will ALWAYS be stored at C:\Program_Name\Calendar.txt so is there any way to default the file selection prompt to C:\Program_Name?

    Thanks,
    Kevin

  2. #2
    Join Date
    Aug 2008
    Location
    Cyprus, EU
    Posts
    50
    Yes you are correct, for security reason you cannot pre-populate an upload field.

    But there is a workaround with a small limitation.
    If they are using Windows and IE, you can use an ActiveX control, e.g. create new ActiveXObject with WSript.Shell object and populate the field.

    The drawback is that the user will get a security warning each time he/she opens the file, but I guess you can explain that to them, and as stated above use Win IE

    I dont use windows, but I think it you tweak the code below according to your needs, it should work

    HTML Code:
    <form>
    <input type="file" name="filename" id="filename"   />
    </form>
    
    <script language=javascript>   
      function window.onload(){   
              document.all.filename.focus();   
              var amyupload_file=new ActiveXObject("WScript.Shell")   
              amyupload_file.sendKeys("C:\\Program_Name\\Calendar.txt")
      }   
    </script>

  3. #3
    Join Date
    Feb 2003
    Location
    AR
    Posts
    2,382
    And ActiveX was the only thing I DIDN'T want to use for this, funnily enough.

    Thanks for your help. Looks like this just can't be done.
    Kevin

  4. #4
    Join Date
    Aug 2008
    Location
    Cyprus, EU
    Posts
    50
    As you said it cant be done.
    If the upload file path and name is constant (as you said) the your only option is JavaScript validation.

    I such a script somewhere but it is simple
    file field onchange, populate a hidden field with file field value and then onsubmit validate the hidden field

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •