www.webdeveloper.com
Results 1 to 11 of 11

Thread: jquery file tree- how to parse file path?

  1. #1
    Join Date
    Mar 2011
    Posts
    9

    jquery file tree- how to parse file path?

    Hi guys,

    I have set up a script on my page which automatically reads the files in a specific directory on the server and displays them in a nice file tree on my website so users can download the files. Here is the script: http://abeautifulsite.net/blog/2008/...ery-file-tree/

    Here is the script in action on my website: http://ligonier-in.org/onlineservice...ents_test.html

    The plugin is working fine as far as finding the files and displaying them. However, the root folder where the files are stored is not the directory you would go to to access the actual files.

    Long story short, the script is trying to download the file at
    http://ligonier-in.org/home/cityofli...pplication.pdf

    I need to 'parse' that url and force it to download the file from:
    http://ligonier-in.org/files/documen...pplication.pdf

    Do you understand what I mean? I pretty much fumbled my way through this whole thing and to be honest I am proud of myself for getting this far. LOL

    I know nothing about javascript and it would be great if someone could spit out a code for me to copy and paste!

    Thanks!

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Why give a link to an invalid location? Change the link path using php to the correct path.

  3. #3
    Join Date
    Mar 2011
    Posts
    9
    In order for the files to display, I have to use the root of /home/cityofligonier/files/

    If I simply change the root to /files/ (which is where I want it to link to) it does not work.

    Here is where I got the idea that it needs to be parsed-
    http://www.mattpaulson.com/2009/05/h...ery-file-tree/

    About 3/4 down the page it says:

    "You might have to write a function to parse the filename that it passes and make some adjustments so it redirects to the right file on the server, but it will work."

  4. #4
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    newRel = oldRel.replace(/home\/cityofligonier\//, "");
    It still makes no sense to give an invalid file name.

  5. #5
    Join Date
    Mar 2011
    Posts
    9
    I'm probably just not explaining myself very well. Or it could be I went about it all wrong to begin with. LOL

    The jquery file tree automatically grabs all of the files in the specified directory for me. So I do not have to do ANY coding when I add files such as meeting minutes, etc. All I do is upload it to to the server and it is automatically displayed in a nice little file tree for the user to download.

    But you have to specify the full root in the code which is not the same path that you would use to access the file.

    For example,
    my index page is /home/cityofligonier/index.html

    So when you go to http://www.ligonier-in.org/index.html, that is the same thing.

    But if you were to try to go to http://www.ligonier-in.org/home/city...ier/index.html, you won't get anything.

    I don't know any other way to explain it, simply because I am not that well versed on any of this.

    Can anyone help?

    I could probably try that javascript code, but I have no clue where to insert it. LOL.

  6. #6
    Join Date
    Mar 2011
    Posts
    9
    I have temporarily solved this problem by copying all of the files from /files/documents_and_forms/ to /home/cityofligonier/files/documents_and_forms.

    However, this is not ideal because now I have to upload each new file to two different directories.

    It would be nice if there was at least a way to automate that process. Can you sync two folders on a remote server? So everything I upload to one directory automatically gets copied to the other?

    Thanks!

  7. #7
    Join Date
    May 2011
    Posts
    2
    I registered for this site just to help you out. I too just implemented jquery file tree on a site and ran into the same problem you have. I am not a web developer/programmer, but I work with one and he was able to help me so I am passing it on to you. It is a simple fix.

    Your code:
    Code:
    window.location = file;
    Replace with:
    Code:
    window.location = file.replace("/home/cityofligonier","");
    Hope this helps.

  8. #8
    Join Date
    Mar 2011
    Posts
    9
    Thanks so much! I really appreciate you taking the time to help me out. This is exactly what I needed!

    Since I'm feeling lucky now, any ideas on how I can get the files to open in a new window?

    Thanks again!

  9. #9
    Join Date
    May 2011
    Posts
    2
    No problem. Try this for opening in new window:

    Code:
    open(file.replace("/home/cityofligonier",""));

  10. #10
    Join Date
    Mar 2011
    Posts
    9
    works perfectly! I can't believe how hard it is to find this stuff via a google search. I have been looking for that simple solution for weeks!

    Thanks again for taking the time to help me. That should do it for this project...

  11. #11
    Join Date
    Jul 2012
    Posts
    1
    @Any of the OPs in this thread: I have same problem except for one thing. Nowhere in my javascript is there a piece of code that matches "window.location = file;". SO I don't know where to apply the fix! I am using (as near as I can tell) the same code from abeautifulsite.com. How can it be so different? I have the identical problem that fought70 was having. Any suggestions would be seriously appreciated! -c-

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles