Solved

File Listing of Local Drive

Posted on 2004-08-27
13
203 Views
Last Modified: 2008-02-01
I have posted this question in the javascript forum, but I am open to any solutions that work, regardless of language.  My problem is as follows:

I have a web-based application written in PHP that stores archive information about stored CDs and DVDs on a MySQL database.  Basic information like job name, description, etc is stored.  It is also possible to upload a log file (created using a 'dir *.* /s > logfile.log' from the dos prompt) which will then be associated with that particular piece of media.  In reality, I don't even store the log files, but I have a PHP script that parses them to find filename, size, etc, then stores them in my MySQL database to speed up the searching process.  This enables, for example, the users to search for all media that has file 'fileName1.txt'.

My problem is that I would like to simplify the process of uploading the log file and give the user the option to simply choose the drive letter that their CD/DVD is in and have a script that will create a file listing of that CD and somehow interact with the server to enable me to insert these new files into my MySQL database.

I'm having some serious problems with this (I have no experience with file operations on a local drive) and I'm beginning to wonder if this is even possible, but I think it must be.  Any help would be very much appreciated.

Thank you for your time.

Chad
0
Comment
Question by:mistaeverly
  • 5
  • 4
  • 2
  • +2
13 Comments
 
LVL 19

Expert Comment

by:RanjeetRain
ID: 11917698
Where will your page be loaded from?

     If it will be loaded from a Webserver, you can not do it. It will be a threat to the system security.

     If you want to do it from a page loaded from the local system, you can do it.


0
 
LVL 3

Author Comment

by:mistaeverly
ID: 11917751
It will be loaded from the webserver.  However, I was thinking of some kind of workaround that would require the users to download a html (or perhaps even a java applet) which could then be run client-side.  This could then find the directory listing and call a PHP page server-side using GET variables.  This PHP page could then take these GET variables and insert them into the database.  Again, I don't know if this is possible... thus the question, but it seems like this general idea might work.  And I stress "might".

As far as security goes for my server, only company machines connected through our VPN have access to these pages, so external security threats are negligible.

Thanks again.

Chad
0
 
LVL 7

Expert Comment

by:lhankins
ID: 11917895
You can do this sort of thing with a signed applet.  It basically goes like this :

1. A user goes to some page on your website.   This page contains the signed applet.   The signed applet needs to be configured so that it requests read access to the local filesystem.

2. The configured JRE plugin for your browser will ask the user if they trust you (the entity specified by the certificate associated with the signed applet).   If they press "yes", then your signed applet will have filesystem permissions.

From that point, you can use the signed applet to communicate back to the serverside...

For more information on signed applets, see :


http://www-personal.umich.edu/~lsiden/tutorials/signed-applet/signed-applet.html





0
 
LVL 19

Expert Comment

by:RanjeetRain
ID: 11917942
Positive outlook. You can have many workable solution.

1.  You can develop an ActiveX control to perform this task. Create the ActiveX control and sign it. Now create your HTML pages and embed an instance of your control in it. When the page loads in the browser, it will download the control from the place mentioned if needed. The first time around the control will install itself. Since its your VPN, you may instruct your users to say "yes" to security dialog. Once your control is loaded, it will have "full access" to the client PC. Play with it any way you like. (Most of the dialers on xxx.com and xxx.net use the same method).

2.  You may do the same with Java Applets. Even for Java Applets the methods remains the same, only the implementation differs. Moreover, Java Applets will work on "all" platforms, whereas ActiveX solution will work only on Windows.


Anything, I need to explain more?
0
 
LVL 21

Expert Comment

by:MogalManic
ID: 11917956
Your html pages can use javascript and the FileSystem object.  The FileSystem object is an UNSIGNED activeX that allows web pages to access the client's file system.  Normally unsigned activeX's cannot be accessed in IE, but you can have your users change the settings (be carefull though, you do NOT want to make corporate IT security mad at you)

To get an Instance of the object add the following to your function:
  var Fo = new ActiveXObject("Scripting.FileSystemObject");

See the following links for example:
http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_20837002.html
0
 
LVL 3

Author Comment

by:mistaeverly
ID: 11917992
So there seem to be many possible solutions.  I would hesitate to use MogalManic's solution (unsigned ActiveX) because of the security risks as well as the extra step of forcing all users to change their IE settings.  The solution need only work on Windows, so certainly the Java applet and ActiveX solutions would both work.  To be quite honest, I have zero experience in either Java or ActiveX, so I don't know which route I should take.  Please advise.

Again, I wish to thank all of you for your help.  I can certainly split up the solution points and even add some if necessary since there are so many of you to respond.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 19

Expert Comment

by:RanjeetRain
ID: 11918363
Go for Java Applet. That's safest and *truely* cross platform.

ActiveX is NOT cross platform. Sorry, If i earlier sounded like that.
0
 
LVL 3

Author Comment

by:mistaeverly
ID: 11918371
I've been looking around, and I literally have no idea where to start.  Should I repost in a Java forum, or are ya'll able to help me?
0
 
LVL 7

Expert Comment

by:lhankins
ID: 11918461
Here's an article which should help you :

   http://www.developer.com/java/data/article.php/3303561

0
 
LVL 3

Author Comment

by:mistaeverly
ID: 11918678
I've been trying to figure this stuff out but it seems that even the simple examples are quite difficult to follow for a Java newbie like myself.  I don't particularly have time to learn Java thoroughly in order to solve this problem.  I've downloaded NetBeans IDE 3.6 from Sun's website and have been messing around with the applet stuff, but I'm having a heck of a time.  Nothing makes you feel quite so ignorant as starting over with a new language.  If anyone could suggest a quick fix that wouldn't require me to master a difficult language, I'd be most appreciative as time is an issue.
Thanks.

Chad
0
 
LVL 19

Expert Comment

by:RanjeetRain
ID: 11918742
Chad,

I wish I could do the code for you, but its not easy. Unless someone has ready code, no one can afford to write it afresh. My advice to you would be, try your hands on it and then post your quesries in form of small small questions in the specific area. For instance, if you decide to use Java Applets, for you the best thing would be to turn to Java experts.

Good luck!
0
 
LVL 4

Accepted Solution

by:
sgalzin earned 500 total points
ID: 11921631
Hi Chad,

Following on what MogalManic said, it is also possible to use an unsigned ActiveX and have the user accept (or deny) it every time, without making global changes to Internet Explorer's settings. If you want to try it out, here's the source code of an HTML example I've made for you (copy and paste it into a text file and rename the file to an HTML file of your choice, such as test.html).

In this example, I've included a maxFiles constant in order to avoid the script running for too long, so make sure you select a drive with less than maxFiles (1000) files on it or the maxFilesMessage ('Too many files in this drive!') will appear.

Cheers,

Stephane.

<html><head><script language="JavaScript"><!--

var fso = new ActiveXObject ( 'Scripting.FileSystemObject' );
var maxFiles = 1000;
var maxFilesMessage = 'Too many files in this drive!';
var counter;

function getDirectoryListingRecursively ( directoryPath )
{
 window.status = 'searching for files in ' + directoryPath;
 var f = fso.getFolder ( directoryPath ), files = new Enumerator ( f.files ), folders = new Enumerator ( f.subFolders ), s = '', d;
 for ( ; !files.atEnd(); files.moveNext () )
 {
  if ( counter ++ >= maxFiles ) return maxFilesMessage;
  s += directoryPath + files.item ().name + '<br />';
 }
 for ( ; !folders.atEnd(); folders.moveNext () )
 {
  d = getDirectoryListingRecursively ( folders.item ().path + '\\' );
  if ( d == maxFilesMessage ) return d;
  else s += d;
 }
 return ( s );
}

function printDirectoryListing ( driveLetter )
{
 counter = 0;
 directoryListing.innerHTML = 'Directory listing : <br />\n' + getDirectoryListingRecursively ( driveLetter + ':\\' );
 window.status = '';
}

function getDriveList ()
{
// this code was adapted from http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/jscolDrives.asp
 var e = new Enumerator(fso.Drives), x, s = '';
 for ( ; !e.atEnd (); e.moveNext () )
 {
  x = e.item ();
  s = s + '<option value=\"' + x.DriveLetter + '\">' + x.DriveLetter + ' - ';
  if (x.DriveType == 3) s += x.ShareName;
  else if ( x.IsReady ) s += x.VolumeName;
  else s += '[Drive not ready]';
 }
 return ( s );
}

//--></script></head>
<body>
Please choose drive : <select id="drive"><script language="JavaScript"><!--
document.writeln ( getDriveList () );
//--></script>
</select>&nbsp;<input type="button" value="Go" onclick="printDirectoryListing (drive.value);"><br />
<div id="directoryListing"></div>
</body></html>
0
 
LVL 3

Author Comment

by:mistaeverly
ID: 11928287
Wow, Stephane, thank you very much.  Initially I got an error instanciating the ActiveX object, but after changing a security setting to "Prompt" instead of "Disabled", it works like a charm.  Now it's just a matter of adapting it a little to suit my purposed.  But you've certainly done most of the heavy lifting.

My thanks to all of you who helped me out.  It's been a pleasure.

Chad
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now