ExpressionEngine SAEF 文件上传到特定目录

发布于 2024-11-14 17:07:05 字数 127 浏览 2 评论 0原文

我正在使用 Expressionsengine 2.x 并尝试为前端用户创建一个文件上传表单,其中上传的文件将存储在以登录用户 ID 命名的文件夹中。我们可以使用 saef 或 safecracker 来做到这一点吗?如果没有还有其他选择。

I am using expressionsengine 2.x and trying to create an file upload form for the front-end user where the file uploaded will be stored in a folder named after the logged in userid. Can we do this using saef or safecracker. If not are there other options.

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

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

发布评论

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

评论(2

清音悠歌 2024-11-21 17:07:05

SafeCracker 捆绑了一个字段类型 SafeCracker 文件,用于创建文件上传字段。字段类型利用您在控制面板中创建的任何文件上传目录

默认情况下,所有上传的文件都将存储在文件上传目录首选项中指定的目录中。

为了将 SafeCracker 文件上传到以登录用户 ID 命名的子文件夹中,您可以开发自定义插件,或利用 与 SafeCracker 兼容的字段类型 - 如果存在可以满足您需求的字段类型。

SafeCracker 的替代方案是使用 Solspace 自由格式模块。但是,即使这样做,您上传的文件仍然会全部保存到同一个文件上传目标,而不是嵌套在子文件夹中。

SafeCracker comes bundled with a fieldtype, SafeCracker File, for creating file upload fields. The fieldtype leverages any File Upload Directories you've created in the Control Panel.

By default, all files uploaded will be stored in the directory specified in the File Upload Directory's preferences.

In order to have SafeCracker files uploaded into a sub-folder named after the logged in userid, you could develop a custom add-on, or leverage a compatible fieldtype that works with SafeCracker -- if one exists to suit your needs.

An alternative to SafeCracker would be to use the Solspace Freeform Module. However, even in doing so, your file uploads would still all be saved to the same File Upload Destination and not nested in sub-folders.

〃温暖了心ぐ 2024-11-21 17:07:05

在这种情况下,由于 SafeCracker 没有任何扩展挂钩,并且据我所知没有任何附加组件允许这种特定行为,因此我将复制 SafeCracker 文件并对其进行更改以添加此功能。否则,您只是从头开始使用自己的“上传文件”字段类型。

您需要查看 ft.safecracker_file.php 中的第 148 行左右,并添加一小段代码来检查是否存在具有登录用户的屏幕名称的目录或您拥有的内容 (查看如何在此处获取此内容),如果没有,则创建它,然后附加该目录姓名到上传路径:

$data = $this->EE->filemanager->upload_file($this->settings['safecracker_upload_dir'].'/'.$users_directory_name, $field_name);

我想这应该可以让你开始。

In this case, since SafeCracker doesn't have any extension hooks, and there are no add-ons I know of that allow this specific behaviour, I'd make a copy of SafeCracker File and alter it to add this functionality. Otherwise, you're just starting from scratch with your own "upload file" fieldtype.

You'll want to look at around line 148 in ft.safecracker_file.php, and add a wee bit of code to check to see if a directory exists with the logged-in user's screen name or what have you (see how to get this here), create it if it doesn't, then append that directory name to to the upload path:

$data = $this->EE->filemanager->upload_file($this->settings['safecracker_upload_dir'].'/'.$users_directory_name, $field_name);

That should get you started I think.

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