No announcement yet.

File Upload to "user" dir?

  • Filter
  • Time
  • Show
Clear All
new posts

  • File Upload to "user" dir?

    Hi there

    I wonder if there's a smart approach to do the following:

    Assume I have a database table full of customer and they have unique incremental IDs. Now for each customer I want to upload files... e.g. scanned correspondance, email, etc....

    However I prefer not to store it in a DB but as normal files on the server. Because like that you can then easily "browse" with your file manager.

    So I've pondered to use directory structures based on the ID and also have additionally symlinks.

    E.g. the actual documents could be stored in a directory like:

    /media/share/clients/1-1000/1/project name/

    I thought splitting up directories into 1000 steps would be good and also seperate for each user according to the project.

    client id 2014 would then be

    /media/share/clients/2001-3000/2014/project name1
    /media/share/clients/2001-3000/2014/project name2
    /media/share/clients/2001-3000/2014/project name3

    Would an file upload mechanism for that be easy to create?

    In a next you might also want to split up for easier-to-navigate

    e.g. you could have a list of all "open" projects like

    /media/share/current projects/CLIENTNAME - PROJECT NAME -> wich would actually be a symlink to /media/share/clients/xxxx-xxxx/xxxx/project xxxx/

    Once you mark the project as closed then the symlink would be deleted.

    also you could setup an sorting by employee. E.g. Tom would only see his clients and not those of Jim

    /media/share/Tom/CLIENTNAME - PROJECT NAME -> wich would actually be a symlink to /media/share/clients/xxxx-xxxx/xxxx/project xxxx/

    I can't figure out any smart way on how to accomplish something like that with SC. The reason I want to split up is that too many files/folders in one folder makes the whole server slow... hence this splitting up and symlinking.

  • #2
    One simple solution would be to save the file to a temporary place and then using php simply move it where you want to have it.
    Basically coding that is rather simple and you can keep using the standard uploader then. Yet then be aware not to make it a database field or to delete the record after the move.

    Another way is to use the events (this is for SC6 so you have to convert it to 7 yourself). I use a grid called grid_filestorage here with subfolder: [sc_upload_folder]
    all you need to do is set that variable at the proper value before entereing the grid.
    //we do this so that {SUBFOLDER} gets update BEFORE the insert, meaning if we display this field then we see the update immediately
    //check if the file already exists if so then dont upload
    if (file_exists($_SESSION['scriptcase']['grid_filestorage']['glo_nm_path_doc'].[sc_upload_folder].{FILENAME})){
    	sc_error_message('This file already exists:' . {FILENAME} . "\r\n");
    //Delete file on delete command but ONLY if it exists this is needed otherwise the file does get removed
    if (file_exists($_SESSION['scriptcase']['grid_filestorage']['glo_nm_path_doc'].[sc_upload_folder].{FILENAME})){
    //Delete file when I delete the record also must be in the OnAfterDelete
    if (file_exists($_SESSION['scriptcase']['grid_filestorage']['glo_nm_path_doc'].[sc_upload_folder].{FILENAME})){