Search in sources :

Example 1 with FormItem

use of lucee.runtime.type.scope.FormItem in project Lucee by lucee.

the class FileTag method actionUploadAll.

public static Array actionUploadAll(PageContext pageContext, lucee.runtime.security.SecurityManager securityManager, String strDestination, int nameconflict, String accept, boolean strict, int mode, String attributes, Object acl, String serverPassword) throws PageException {
    FormItem[] items = getFormItems(pageContext);
    Struct sct = null;
    Array arr = new ArrayImpl();
    for (int i = 0; i < items.length; i++) {
        sct = _actionUpload(pageContext, securityManager, items[i], strDestination, nameconflict, accept, strict, mode, attributes, acl, serverPassword);
        arr.appendEL(sct);
    }
    return arr;
}
Also used : Array(lucee.runtime.type.Array) FormItem(lucee.runtime.type.scope.FormItem) ArrayImpl(lucee.runtime.type.ArrayImpl) Struct(lucee.runtime.type.Struct)

Example 2 with FormItem

use of lucee.runtime.type.scope.FormItem in project Lucee by lucee.

the class FileTag method actionUpload.

/**
 * read source file
 * @throws PageException
 */
public void actionUpload() throws PageException {
    FormItem item = getFormItem(pageContext, filefield);
    Struct cffile = _actionUpload(pageContext, securityManager, item, strDestination, nameconflict, accept, strict, mode, attributes, acl, serverPassword);
    if (StringUtil.isEmpty(result)) {
        pageContext.undefinedScope().set(KeyConstants._file, cffile);
        pageContext.undefinedScope().set("cffile", cffile);
    } else {
        pageContext.setVariable(result, cffile);
    }
}
Also used : FormItem(lucee.runtime.type.scope.FormItem) Struct(lucee.runtime.type.Struct)

Example 3 with FormItem

use of lucee.runtime.type.scope.FormItem in project Lucee by lucee.

the class FileTag method getFormItem.

/**
 * rreturn fileItem matching to filefiled definition or throw a exception
 * @return FileItem
 * @throws ApplicationException
 */
private static FormItem getFormItem(PageContext pageContext, String filefield) throws PageException {
    // check filefield
    if (StringUtil.isEmpty(filefield)) {
        FormItem[] items = getFormItems(pageContext);
        if (ArrayUtil.isEmpty(items))
            throw new ApplicationException("no file send with this form");
        return items[0];
    }
    PageException pe = pageContext.formScope().getInitException();
    if (pe != null)
        throw pe;
    lucee.runtime.type.scope.Form upload = pageContext.formScope();
    FormItem fileItem = upload.getUploadResource(filefield);
    if (fileItem == null) {
        FormItem[] items = upload.getFileItems();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < items.length; i++) {
            if (i != 0)
                sb.append(", ");
            sb.append(items[i].getFieldName());
        }
        String add = ".";
        if (sb.length() > 0)
            add = ", valid field names are [" + sb + "].";
        if (pageContext.formScope().get(filefield, null) == null)
            throw new ApplicationException("form field [" + filefield + "] is not a file field" + add);
        throw new ApplicationException("form field [" + filefield + "] doesn't exist or has no content" + add);
    }
    return fileItem;
}
Also used : PageException(lucee.runtime.exp.PageException) ApplicationException(lucee.runtime.exp.ApplicationException) Form(lucee.runtime.type.scope.Form) FormItem(lucee.runtime.type.scope.FormItem)

Aggregations

FormItem (lucee.runtime.type.scope.FormItem)3 Struct (lucee.runtime.type.Struct)2 ApplicationException (lucee.runtime.exp.ApplicationException)1 PageException (lucee.runtime.exp.PageException)1 Array (lucee.runtime.type.Array)1 ArrayImpl (lucee.runtime.type.ArrayImpl)1 Form (lucee.runtime.type.scope.Form)1