Skip to content

Instantly share code, notes, and snippets.

@RyanCopley
Created February 6, 2013 03:58
Show Gist options
  • Save RyanCopley/4720143 to your computer and use it in GitHub Desktop.
Save RyanCopley/4720143 to your computer and use it in GitHub Desktop.
class FileManager
private $user
FileManager(int userid [,mixed options]) instantiates with a user name, should call the function setUser(id userid) below
FileManager(str user [,mixed options]) instantiates with a user name, should call the function below
setUser(str user [, mixed options]) - Calls the function below after fetching the ID of the user
setUser(int userid [, mixed options]) - Should set the user variable, and check to see if the current user is the one provided. This should clear all data for this object upon setting
getUser() - Return the user model that is loaded for this FM.
getUserFolder() - Return the folder model for the users root.
fileExists(str filename) - Returns if this user has the file available
fileFind(str filename [,str startfolder [, int recursive]]) - regex compatible file search via filename. Should return an array of results
ALSO:
File controllers shit
getFileHitCount() - Returns the download count
getFileSize() - returns the file size. Spectrenectre said to make sure we store it in the db...
getFileDate() - returns the file date. Spectrenectre said to make sure we store it in the db...
isFileLocked() - Returns if the file is locked. Things like the users avatar and various other things may be locked, disabling the user from directly modifying them.
isSystemFile()
isDeletable()
//for filemanager::getFileList so we can iterate over them and not worry about object type
isFolder() - false
isFile() - true
fileUpload() - I'm not sure how to handle this. Passing all the data via value is a bad idea. Make sure you don't go crazy on the memory...
fileDownload() - Increments the download counter and redirects the user to the file. It is important to note that if you use header("Location" ...) that nothing may be printed out before this. It might be useeful to look at this and try to come up with some solution: http://www.webdeveloper.com/forum/showthread.php?185111-using-header()-after-output-was-sent
getFileDownloadURL(file) - Returns the download link of a file. This should go somewhere that ends up calling fileDownload()... probably an ajax call or something of the sorts?
systemOverrideWriteRestrictions() - Disables any security for getIsUploadable and folderIsWritable. This is for internal usage only for things like mail attachments, games, so the site can handle moving files to that folder. We do not want the users touching this folder.
folder models, should have a function to fetch all files in the folder
isLocked() - Returns if the folder is locked. Things like the users avatar and various other things may be locked, disabling the user from directly modifying them. System folders will all be locked.
isSystemFolder()
//for filemanager::getFileList so we can iterate over them and not worry about object type
isFolder() - true
isFile() - false
getFileList()
systemOverrideWriteRestrictions() - Disables any security for getIsUploadable and folderIsWritable. This is for internal usage only for things like mail attachments, games, so the site can handle moving files to that folder. We do not want the users touching this folder.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment