On Apr 14, 3:11 pm, Doug Reeder <reeder...@gmail.com> wrote:
> I'd like to allow the user to select a file from his/her filesystem,  
> and process it locally.  Due to heightened security (or at least the  
> semblance thereof) the value of a file input element is just the name  
> of the file, not the full path, in many modern browsers, so the file  
> path can't be turned into a "file:" URL that can be loaded via AJAX.    
> Is there a way to access the contents of the file using Prototype?

Nothing to do with AJAX (where AJAX is a pseudonym for
xmlHttpRequest).  If it's an XML document, it can be loaded using a
fairly simple script:

function loadXMLFile(fileName) {
  var xmlDoc;

  // W3C compliant
  if (document && document.implementation &&
      document.implementation.createDocument ) {
    xmlDoc = document.implementation.createDocument("","",null);

  } else {

    // IE model
    try {
      xmlDoc = new ActiveXObject('Msxml2.DOMDocument');
    } catch( e){}

  if (xmlDoc) {
    xmlDoc.async = false;

    try {
      var loadOK = xmlDoc.load(fileName);
    } catch(e) {}

  return loadOK? xmlDoc : null;

Call using the value of the file input, it returns an XML document or
null if the load failed.

You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to