开发者

ExpressionEngine SAEF File upload to specific directoy

I am using expressionsengine 2.x and tr开发者_StackOverflow中文版ying 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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜