I've been working with Drupal for about a month or so now and have finished up my first module. It's a file browser module I developed for an industry trade site to manage a massive amount of downloadable assets. I have it up an running at http://jamieruderman.com if you'd like to try it or download the code. I just wanted to share and see if anyone thought that it would be suitable for mass consumption? I just applied for a CVS account...

Anyway, since I'm getting so much from Drupal, I figured I'd give what little I have back!

Thanks, Jamie.

Comments

cooperaj’s picture

Thats really nice. I like it.

It'd be nice to have the ability to move files around though, and the ability to upload zipped directory structures (automatically unzipped on arrival) would rock.

How are the uploads handled? Using upload.module or the filemanager.module api.
Is the folder structure actually on disk? or stored as meta-info?

IMO this would be uber nice if it stored the structure as meta-info and used the filemanager api but then that's scratching my own itch, not yours ;-).

Congrats on a great first module

JamieR’s picture

Thanks for the nice words.

I'd like to move files around too... it wouldn't be hard to implement, you would just have to be able to select a file and then a target directory... just wasn't critical for my uses. Uploads are handled with the file_save_upload() function in file.inc... I couldn't figure out how to enable the whole upload.module with all the ajax goodness... so went for the simple way...

I'm not sure exactly what you are talking about with regards to the meta-info and the filemanager api... all the files in a flat directory, then having the hierarchy stored in the database?

This was basically just a way to browse files uploaded via FTP, we've got thousands of files online... way more than we'd want to try and submit via a web browser. The zipped directory function would be cool too... although... if you're getting that advanced FTP is probably within your toolset? We just needed some rudimentary editing functionality for our purposes. :)

Thanks for the feedback!

nevets’s picture

I really like the way it looks on your site so I downloaded it to try out. Found a minor problem with filebrowser.install in that the install function is call minutes_install instead of filebrowser.install. I also do not see the "directory tree" running Drupal on a windows box.
I would like to get it running so it works with existing node types (like the standard upload module).

JamieR’s picture

Whoops! That filebrowser.install was a last minuite addition and haddn't been tested. I was adding the tables manually. Well you can see where I lifted the code from. :) I just fixed it.

Unfortunately I don't have any windows servers available to me to test on that platform. We're all Mac and Linux... if you fix the problem let me know and I'll update the files... I've never worked with the CVS system, but I assume that once that is up it can all be managed there.

jivyb’s picture

I must be missing something obvious, but when you're adding a filebrowswer node, how do you tell it which directory you want "browsed"? Right now, it just shows all the files in my root.

www.robcomm.net

JamieR’s picture

Hmmm... sounds like it's mis-behaving for you... or perhaps you don't have your "files" directory set in the general settings? It should create a directory for you in your "files" directory based on the title of the node. After you have created the node go to the edit screen and it will list where the new directory is. Hope that helps!

See here under "Filebrowser settings": http://jamieruderman.com/?q=node/8/edit

jivyb’s picture

Thanks. That helped. What I see in my node edit screen is just what's in bold in yours (no file paths). I think the problem is that the install file isn't installing the tables. The files directory is set and has 777 permissions. I tried running the update.php script but that didn't help. Can you give me a mysql file and I'll load them manually?

www.robcomm.net

JamieR’s picture

Sorry the .install isn't working - I guess I need to test that! Here is the mySql table code:

CREATE TABLE {node_filebrowser} 
	(
		vid INT(4) UNSIGNED DEFAULT '0' NOT NULL ,
		nid INT(4) UNSIGNED DEFAULT '0' NOT NULL ,
		_filepath VARCHAR(255) NOT NULL ,
		_thumbs BOOL DEFAULT 'FALSE' NOT NULL ,
		_modify BOOL DEFAULT 'FALSE' NOT NULL ,
		PRIMARY KEY (vid,nid)
	) 
	TYPE = MYISAM /*!40100 DEFAULT CHARACTER SET utf8 */

Hmmm... I can't get the install file to work. Not much documentation out there on it either... This was all I could find:
http://api.drupal.org/api/4.7/function/hook_install it would appear that the code is not getting called.

Anyone know what's missing?

/**
 * Implementation of hook_install()
 */
function filebrowser_install() {
	drupal_set_message('Installing database tables');
  switch($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {node_filebrowser} 
				(
					vid INT(4) UNSIGNED DEFAULT '0' NOT NULL ,
					nid INT(4) UNSIGNED DEFAULT '0' NOT NULL ,
					_filepath VARCHAR(255) NOT NULL ,
					_thumbs BOOL DEFAULT 'FALSE' NOT NULL ,
					_modify BOOL DEFAULT 'FALSE' NOT NULL ,
					PRIMARY KEY (vid,nid)
				) 
				TYPE = MYISAM /*!40100 DEFAULT CHARACTER SET utf8 */"
      );
			drupal_set_message('MySQL database tables installed');
      break;
      
    case 'pgqsl':
      db_query("CREATE TABLE {node_filebrowser} 
			  (
				  vid int4 NOT NULL DEFAULT 0,
				  nid int4 NOT NULL DEFAULT 0,
				  _filepath varchar(255) NOT NULL DEFAULT ''::character varying,
				  _thumbs bool NOT NULL DEFAULT false,
				  _modify bool NOT NULL DEFAULT false,
				  CONSTRAINT filebrowser_nid PRIMARY KEY (vid, nid)
				) 
				WITHOUT OIDS;"
      );
			drupal_set_message('postgreSQL database tables installed');
      break;
  }
}

Thanks - Jamie.

nevets’s picture

If I understand correcty it;s because the module is installed already. Even if you just disable the module and entry stays in the system table and drupal thinks you are re-enabling the module versus installing from there on. You can go into the system table an delete the entry(s) for you module. I think that will help.

JamieR’s picture

You were right - deleted the system record of the module and it ran... then tracked down a typo in the 'pgsql' case... must have been in the code that I copied... I don't remember changing that. Thanks!

jivyb’s picture

Thanks. That worked when I removed the brackets around node_filebrowser. I'm liking this module so far:)

www.robcomm.net

elly’s picture

wow, that IS really nice. it might really help me with the site i'm currently migrating into drupal.

couple of questions:

how customizable is the display?
can things always be expanded, instead of expandable?
is there any way show a title and description for a file instead of just the filename?

what i really need is a combination of this and the attachment/upload file list - where it browses files on the filesystem like yours does, lets users upload new files, and stores and displays titles and descriptions for files. and, in a perfect world, lets users categorize and organize file lists, with headers, subheaders, and tags or categories.

the site i'm working on has tons of legal documents, briefs and etc, in .pdf format, that need to be displayed in well organized lists, with subheaders.

JamieR’s picture

The display is customizable through the filebrowser.css file... it's pretty flexible - although I'm starting to think that I should have just created the sturcture with div tags instead of ul and li so that I could that the rows highlight when you mouse over them...

You could have the folders all auto expand if you wanted, but that would kinda negate the fun of the AJAX. You would just have to add some javascript to the nesteddir_handler to tell it to call itself as it was running... although now that I think of it... I'm not sure how that would work... recursive AJAX calling itself... ?!

I'm working on finding a way to save more information with the files like a shord description and an uploaded by field or something... I want it to save that info to the files themselves... not write to database, but I'm still not sure if it can be done.

JamieR’s picture

It seems a "filebrowser" from the past has shown up again... so I need a new name - how about:

fileshare_node

or

filelist_node

Anyone have an opinion / other suggestion?
Thanks! Jamie.

jivyb’s picture

Another "it would be fantastic if" comment: I would like to restrict download permission by role (only registered users, for example). It would be great if this were in the permissions list in the access control list.

Thanks for your module. I like the name fileshare, btw.

TurboChef’s picture

I can't get the thing to work. I enabled the module, but then where is the menu to show your files?

I'm running Apache 2.2.0, MySQL 5.0.21, and PHP 5.1.4 on a Windows 2003 server. I have /files set up as the root of my documents. After I enabled it, I tried to create a new fileshare. I see various errors in the log:

Table 'drupal.node_fileshare' doesn't exist query: SELECT _filepath, _modify, _thumbs FROM node_fileshare WHERE vid = 5 in D:\Intranet\includes\database.mysqli.inc on line 121

Table 'drupal.node_fileshare' doesn't exist query: SELECT _filepath, _modify, _thumbs FROM node_fileshare WHERE vid = 5 in D:\Intranet\includes\database.mysqli.inc on line 121.

Table 'drupal.node_fileshare' doesn't exist query: SELECT _filepath, _modify, _thumbs FROM node_fileshare WHERE vid = 5 in D:\Intranet\includes\database.mysqli.inc on line 121

readdir(): supplied argument is not a valid Directory resource in D:\Intranet\modules\fileshare\fileshare.module on line 560

sort() expects parameter 1 to be array, null given in D:\Intranet\modules\fileshare\fileshare.module on line 563.

closedir(): supplied argument is not a valid Directory resource in D:\Intranet\modules\fileshare\fileshare.module on line 613

Thinking the .install file wasn't working yet (because the errors seem to indicate the table isn't there), I tried importing the .mysql file into my Drupal table using MySQLAdmin, and I got this:

SQL query: 

CREATE TABLE node_fileshare(

vid INT( 4 ) UNSIGNED DEFAULT '0' NOT NULL ,
nid INT( 4 ) UNSIGNED DEFAULT '0' NOT NULL ,
_filepath VARCHAR( 255 ) NOT NULL ,
_thumbs BOOL DEFAULT 'FALSE' NOT NULL ,
_modify BOOL DEFAULT 'FALSE' NOT NULL ,
PRIMARY KEY ( vid, nid ) 
) TYPE = MYISAM 

MySQL said:  

#1067 - Invalid default value for '_thumbs'

So I'm a bit stuck - any documentation you can pass on for installation and configuration? Also, are all the ._xxxxxx files necessary to be there? It seems you made all these on a Mac (due to the .DS_Store file being there), but there's a duplicate [in name] of every file in your archive.

Thanks again - looks like a cool module. I hope I can use it soon.

John @ Turbochef

JamieR’s picture

Sorry about that - I'm a postgreSQL guy, but was able to get that MySQL code to work through phpMyAdmin... but I looked back at the table and it was described slightly different, so I've updated that code. Please download it and try again. Let me know what you find. I've worked out some security issues so I'll probably get it up in the CVS area soon.

Oh and RE: mac zip files... yeah - I was just being lazy ziping the thing... I've made the proper tar.gz file this time... :)

Jamie.

TurboChef’s picture

Jamie,

OK, we're making progress. The .install file didn't create the "node_fileshare" table, but MySQLAdmin imported that into my Drupal DB without issues. I now have a couple of issues...

I selected Create Content, then fileshare...

I added a new share called Shared Files, and checked both boxes

It created a shared_files6 folder in my Files directory, and _preview inside that. I then tried to upload a small PDF into that folder, and I got this:

Fatal error: Call to undefined function upload_space_used() in D:\Intranet\modules\fileshare\fileshare.module on line 393

1. Why does it add a number to the end of the folder name?

2. Could you figure out if that error is a code issue, or maybe something I did?

and some other questions (because I'm really interested in your module)...

3. If you already have a folder in place, would you need to create a fileshare, then move all your existing files into it?

4. Can we add a description field in the table so you can associate a description with each folder or file? Or is this just for displaying the contents of a folder of items?

Thanks for the quick response - again, great work!

John

JamieR’s picture

That was some left over code from the image.module that I missed. I guess it was'nt giving me an error because I have that module running... but it should be removed.... now if I could just figure out how to use this darn CVS system I would update my files...

Oh, and it adds the number at the end of the folder name to ensure it contains a unique identifier. That is the node id.

Regarding a folder that is already in place, you are correct - just copy the files over into it. Or you could delete the folder that the fileshare created and rename yours to be the same as the old one... and just make the _previews subfolder.

Unfortunately there is currently no way to add a description field to the files... something I would like, but would be rather difficult.

TurboChef’s picture

That line said:

	$total_usersize = upload_space_used($user->uid) + $filesize;

Just to make sure I deleted the correct line.

I created a new "files" fileshare and I moved the folders and files to that folder on the server. The folders and files showed up correctly. Nicely done, Jamie.

A couple of other issues worth mentioning - for some reason, the delete icon and the mouseover highlight isn't showing up in IE6, but they show up plain as day on Firefox. Also, when going back in to edit the fileshare, it gives a message:

RENAMING ERROR - from "files/files7" to "files/files7"

But if you're making a change to the entry (the description, for instance), the change DOES go through.

One suggestion - under access control, you have "modify files" listed - is that actually "delete files"? I wouldn't think you could modify a file in place, could you?

I'm about to enable Organic Groups to create departments for my site (it's a corporate intranet) and I THINK that your module would work as a "Organic groups file area" thing, if you created a fileshare with menu placement under each group name. I'll let you know how that works. I suppose you're working on access rights per folder/file as well?

Oh, since you are going through so many revisions (this is a new module, after all), you may want to place a version number and date/time modified in the comment area at the top, and/or the name of the tar.gz you create.

JamieR’s picture

The renaming errors are usually having something to do with file permissions. Perhaps you changed the default permissions of that folder?

The "modify files" (perhaps it should say "fileshare") is called modify because it also enables the upload and create folder functionality - as well as the delete ability. It's not an ideal name though...

I think the version numbering is supposed to be taken care of by the CVS software, but I'm a total newbie to that system and still haven't gotten it figured out... soon though... soon.

Thanks for the feedback. I'm on Mac and Linux most of the time so don't get to test too much on windows. I'll look into the IE problems... need that delete icon to show up. Though I could live with them not having the highlight bells and whistles...

At the moment I just want to sort out the bugs and take a break, as I've got A LOT of work piling up. I'm supposed to have some basic form of our Marmot intranet in place Friday! Yikes! :)