using QFileControl instead of QFileAssets
Mon, 01/30/2012 - 03:03
Hi.
I want to use QFileControl for uploading files. I find I cannot limit filetypes like is done with QFileAssets.
I don't need the blank image and displayed image with the QFileAssets control but since this will be open to the public, I certainly want to limit the files to pdf and docs.
Is it possible? Something simple I hope. :-)
Thanks
David

Hello David,
If you want something simple use the Form_Validation method like in the code below. You have to set the CausesValidation property of your submit button to 'true' and render the file control element with:
<?php$fileControl->RenderWitherror();
?>
The advantage of this method is that it is very simple and uses the framework functionality very well. Instead of checking the file extension you might want to check the mime type as in QFileAssetControl. This method may turn out user unfriendly when the to be uploaded files get big as the action happens on the server side. Thus, when the file has been uploaded already. In that case you unfortunately need to do some java scripting.
<?php
public function Form_Validate(){
$res = parent::Form_Validate();
$info = pathinfo($this->fileControl->FileName);
$ext = strtoupper($info['extension']);
if($ext !== 'PDF'){
$this->filControl->Warning = "Wrong file type";
return false;
}
return $res;
}
?>
Cheers
Helge