Application for sharing documents with MVC

I was assigned a new task for the client, a document-sharing application that should be executed using the MVC design pattern. Here are the requirements:

  • Download and upload files using a browser

  • Save the document in db if these are safer documents stored in a directory with password options enabled or available

  • Each user will have their own document catalog / workspace from which he will be able to exchange documents with other users. and a public shared area for sharing and downloading files

  • The super administrator will be able to track the file upload logging for monitoring purposes.

I have an approximate idea, but I would really like to know your thoughts about the above points, especially about what is bold there.

The third paragraph above is the most important, and I'm not sure where to start and how to register downloads.

I basically ask for details on the implementation of the third and fourth points.

+3
source share
1 answer

This is how I implement this with CakePHP and it works well. First, I make sure the application code is located above the public html directory so that it is not open to the Internet. Thus, basically, the only files that users have direct access to are index.php file, css / js and image files.

:

function beforeSave() {
    extract($this->data['Upload']['file']);
    if(isset($name) and !empty($name)) {
        $filename = time().'-'.$name;
        if ($size && !$error) {
            move_uploaded_file($tmp_name, APP . 'media/files/' . $filename);
            $this->data['Upload']['file'] = $filename;
            $this->data['Upload']['name'] = $name;
            $this->data['Upload']['file_type'] = $type;
        }
    } else {
        // remove the photo so it is not updated
        unset($this->data['Upload']['file']);
    }
    return parent::beforeSave();
}

function beforeDelete() {
    $data = $this->read(null, $this->id);
    if( is_file( APP . 'media/files/' . $data['Upload']['file'])) {
        unlink(APP . 'media/files/' . $data['Upload']['file']);
    }
    return true;
}

. // , . , , , -.

, , , "shareable", , , .

+3

Source: https://habr.com/ru/post/1760091/


All Articles