Skip to content

Instantly share code, notes, and snippets.

@RyanCopley
Created February 6, 2013 03:42
Show Gist options
  • Save RyanCopley/4720046 to your computer and use it in GitHub Desktop.
Save RyanCopley/4720046 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.
getFileList() - Returns an array of File models
getFileByName(str filename) - Returns a file model if it exists by name for the user, null if it doesnt
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:
(These models should get a reference back to the File Manager, for the systemOverrideWriteRestrictions)
File models/controllers shit
getFileDownloadURL(file) - Returns the download link of a file
getHitCount(file) - Returns the download link of a file
getFileSize(file) - returns the file size. Spectrenectre said to make sure we store it in the db...
getFileDate(file) - returns the file date. Spectrenectre said to make sure we store it in the db...
getFileIsLocked(file) - 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.
fileUpload() - I'm not sure how to handle this. Make sure you fetch the file object and do an update if it already exists.
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
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
getFolderIsLocked(str foldername) - 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.
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