validating multiple fileupload with different filetypes

Hi,I am new to the Yii framework, I am developing an application in which user can create competitions and other users can submit files to that competitions. When creating a competition user can specify the type of files the participants can upload and if it is mandatory or not. Following is the database structure for custom fields defined by the competition creator and the custom data submitted by the participants. Here the fieldType represents four filetype - 1 => Image, 2 => Document, 3 => Video, 4 => Audio.

CREATE TABLE IF NOT EXISTS `tbl_custom_fields` (

  `customFieldId` int(50) NOT NULL AUTO_INCREMENT,

  `competitionId` int(50) NOT NULL COMMENT 'CONSTRAINT FOREIGN KEY (competitionId) REFERENCES tbl_competitions(competitionId)',

  `fieldLabel` varchar(255) NOT NULL,

  `fieldType` int(5) NOT NULL,

  `required` int(1) NOT NULL,

  PRIMARY KEY (`customFieldId`)


CREATE TABLE IF NOT EXISTS `tbl_custom_data` (

  `customDataId` int(50) NOT NULL AUTO_INCREMENT,

  `submissionId` int(50) NOT NULL COMMENT 'CONSTRAINT FOREIGN KEY (submissionId) REFERENCES tbl_submissions(submissionId)',

  `customFieldId` int(50) NOT NULL COMMENT 'CONSTRAINT FOREIGN KEY (customFieldId) REFERENCES tbl_custom_fields(customFieldId)',

  `value` varchar(255) NOT NULL,

  PRIMARY KEY (`customDataId`)

) ;

I have created the curd functions using the Gii tool. I want to show the submission form to the user according to the fieldType defined for each competition and , for example it will be Video,Document and Image and validate the file extensions for each fields and also required fields.I tried different approaches but unsuccessful in creating a form and its action with proper Yii type validation and insertion. Can anybody please share some sample code or suggest any solution for this?


Is this what you are looking for?

Not really, My scenario is different. It has multiple file upload fields, also different file types. I wanted to validate the file extensions according to filetypes.Also dynamically check some fields as mandatory. Thanks for your reply.

You can use that tutorial. Just put repetitive fields and that is fine.

About your extension.

you have 2 ways, one is to use different validations in your model;

the other way is to use php’s or CUploadedFile’s getExtension() (I forgot the details…you gotta check it yourself in Yii’s documents)

In this way, you can also get the extension and then do your own stuff.

Anyway, read qiang’s how to upload file use a model tutorial first.