SebTags 1.0 Documentation: Folders

Folders

By taking advantage of some attributes in cf_sebForm, you can reduce the amount of code needed in each cf_sebField that handles file uploads. This is especially useful if you have multiple file uploads that are all in subfolders of one main upload location.

For example, you might upload all files to the "/files/" folder. Then resumes might go in the "/files/resumes/" folder and avatars might go in the "/files/avatars/" folder.

You can use the "UploadBrowserPath" and "UploadFilePath" attributes of cf_sebForm to set this central location for file uploads:

<cf_sebForm UploadBrowserPath="/files/" UploadFilePath="#ExpandPath('/files/')#">
...
</cf_sebForm>

Now cf_sebForm know where to put all of you files.

Without using UploadBrowserPath and UploadFilePath, your code would like like this:

<cf_sebForm>
   <cf_sebField type="file" name="MyFile" destination="#ExpandPath('/files/myfiles/')#" urlpath="/files/myfiles/">
   <cf_sebField type="submit" label="Submit">
</cf_sebForm>

Using UploadBrowserPath and UploadFilePath, it would look like this:

<cf_sebForm UploadBrowserPath="/files/" UploadFilePath="#ExpandPath('/files/')#">
	<cf_sebField type="file" name="MyFile" folder="myfiles">
	<cf_sebField type="submit" label="Submit">
</cf_sebForm>

The file from the "MyFile" field would now be uploaded to "/files/myfiles/".

While this doesn't save any code if you only have one file field, it can save substantial code as you add additional file fields.

Using Global Variables

Remember, cf_sebForm can use request variables to set default values for any attributes.

So, you could include the following code in Application.cfm/cfc:

<cfscript>
request.cftags = StructNew();
request.cftags.cf_sebForm = {UploadBrowserPath="/files/",UploadFilePath=ExpandPath("/files/")};
</cfscript>

After which your form could be written as:

<cf_sebForm>
	<cf_sebField type="file" name="MyFile" folder="myfiles">
	<cf_sebField type="submit" label="Submit">
</cf_sebForm>

Nested Folders

If you want to nest folders, use a comma as the path delimiter. For example, if you wanted to upload avatars to "/files/users/avatars/", you could using the following code:

<cf_sebForm>
	<cf_sebField type="file" name="MyFile" folder="users,avatars">
	<cf_sebField type="submit" label="Submit">
</cf_sebForm>