使用 MVC 的文档共享应用程序

发布于 2024-09-14 08:44:29 字数 442 浏览 2 评论 0原文

客户给我分配了一个新任务,一个使用 MVC 设计模式制作的文档共享应用程序。以下是要求:

  • 使用浏览器上传和下载文件

  • 如果文档更安全,则将文档存储在数据库中,否则存储在目录中带选项启用密码或无需密码即可访问

  • 每个用户都将拥有自己的文档目录/工作区,他也可以在其中与其他用户共享文档。以及用于共享和上传文件的公共共享区域

  • 超级管理员将能够监控文件上传日志记录以达到监控目的。

我有一个粗略的想法,但我真的很想知道您对上述几点的想法,特别是上面粗体显示的内容。

上面的第三点是最重要的,我不确定从哪里开始以及如何记录上传。

我基本上是在询问第三点和第四点的实施细节。

I have been assigned a new task by a client, a document sharing application to be made using the MVC design pattern. Here are the requirements:

  • Uploads and downloads files with a browser

  • Store the document in db if that are more secure documents else store on the directory with options of password enabled or accessible without password

  • Every user will be have own document catalog / workspace from where he can be able to share documents with other users as well. and public shared area to share and upload files

  • Super admin will be able monitor the file upload logging for monitoring purpose.

I have rough idea but I would really like to know your thoughts about above points especially what is in bold up there.

The third point above is most important and I am not sure where to start from and how to go about logging the uploads.

I am basically asking for implementation details about the third and fourth points.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

謸气贵蔟 2024-09-21 08:44:29

以下是我使用 CakePHP 实现此功能的方法,效果很好。首先,我确保我的应用程序代码位于公共 html 目录之上,这样它就不会暴露在网络上。所以基本上,用户可以直接访问的唯一文件是index.php 文件、css/js 和图像文件。

然后,我更新文件管理模型以动态保存和删除文件:

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;
}

这将管理文件上传并将所有命名信息放入数据库中。由于 app/media/files 目录无法通过网络访问,因此我不必保护该目录。这意味着无论用户想要什么文件,他们都必须从网站访问它。

然后,您所要做的就是确保模型表有一个“可共享”标志,供用户指示该文件可供全世界访问,然后任何人都可以查看该文件并下载它。

Here is how I implement this with CakePHP and it works nicely. First, I make sure my app code sits above the public html directory so that it is not exposed to the web. So basically, the only files the users have direct access to is the index.php file, the css/js and image files.

Then, I update my file management model to save and delete files on the fly:

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;
}

This will manage the file upload and put all of the naming information into the database. And since the app/media/files directory is not accessible to the web, I do not have to protect the directory. It means that no matter what file the user wants, they have to access it from the website.

Then, all you have to do is make sure the model table has a "shareable" flag for the user to indicate that the file is accessible to the world, and then anyone can see the file and download it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文