GetFileField
string CForm::GetFileField( int answer_id, mixed width = "", string file_type = "IMAGE", int max_file_size = 0, mixed file_id = "", string add_to_file = "class=\"inputfile\"", string add_to_checkbox = "class=\"inputcheckbox\"", )
Returns HTML code for the file upload field. This field is intended to input "image" or or "file" type answer.
This method can be used in both the form for creating new result, and form for editing of existing result. Non-static method.
Note
Name of resulting HTML field will be generated by the following mask:
form_file_type_answer_id
Method parameters
Parameter | Description | Available from version |
---|---|---|
answer_id | ID of answer. | |
width | Width of resulting file upload field:
<input type="file" size="width" ...> Optional parameter. Empty by default. |
|
file_type | Type of file. The following values are possible:
|
|
max_file_size | Максимальный размер загружаемого файла (в байтах). Параметр необязательный. По умолчанию - 0 (без ограничений). |
|
file_id | ID of uploaded (edited) file. Optional parameter. Empty by default. |
|
add_to_file | Custom HTML, to be added to the HTML tag of file upload field:
<input type="file" add_to_file ...> Optional parameter. Default value - "class=\"inputfile\"". |
3.3.10 |
add_to_checkbox | Custom HTML to be added to the HTML tag of flag to delete an edited file:
<input type="checkbox" add_to_checkbox ...> Optional parameter. Default value - "class=\"inputcheckbox\"". |
3.3.10 |
PARAM_TEXT | Optional parameter. Deleted starting from version 4.0.4 | 3.3.10 |
See Also
Examples of use
<? /******************************************* Result edit *******************************************/ $RESULT_ID = 12; // Result ID ?> <form action="" method="POST"> <table> <tr> <td>Photo:</td> <td><? /************************************************************ Image ************************************************************/ // array describing the answer field // contains minimally-required fields $arAnswer = array( "ID" => 607, // ID of the field with answer to the question "Photo" "FIELD_WIDTH" => 10, // field width "FIELD_PARAM" => "" // field parameters ); // get parameters of uploaded file if ($arFile = CFormResult::GetFileByAnswerID($RESULT_ID, $arAnswer["ID"])): // if the file is retrieved... if (intval($arFile["USER_FILE_ID"])>0): // and is an image... if ($arFile["USER_FILE_IS_IMAGE"]=="Y") : // display the image echo CFile::ShowImage( $arFile["USER_FILE_ID"], 0, 0, "border=0", "", true); endif; echo "<br><br>"; endif; endif; // display field for file download echo CForm::GetFileField( $arAnswer["ID"], $arAnswer["FIELD_WIDTH"], "IMAGE", 0, // maximum file size is no limited $arFile["USER_FILE_ID"], $arAnswer["FIELD_PARAM"]); ?></td> </tr> <tr> <td>CV:</td> <td><? /************************************************************ Random file ************************************************************/ // array describing answer field // contains minimally-required fields $arAnswer = array( "ID" => 610, // ID of field for answer to question "CV" "FIELD_WIDTH" => 10, // field width "FIELD_PARAM" => "" // field parameters ); // get parameters of uploaded file if ($arFile = CFormResult::GetFileByAnswerID($RESULT_ID, $arAnswer["ID"])): // if the file is retrieved... if (intval($arFile["USER_FILE_ID"])>0): // display information about the file ?> <a title="File view" target="_blank" class="tablebodylink" href="/bitrix/tools/form_show_file.php?rid=<?=$result_id?>&hash=<?echo $arFile["USER_FILE_HASH"]?>〈=<?=LANGUAGE_ID?>"><?=htmlspecialchars($arFile["USER_FILE_NAME"])?></a> (<? $a = array("b", "Kb", "Mb", "Gb"); $pos = 0; $size = $arFile["USER_FILE_SIZE"]; while($size>=1024) {$size /= 1024; $pos++;} echo round($size,2)." ".$a[$pos]; ?>) [ <a title="<?echo str_replace("#FILE_NAME#", $arFile["USER_FILE_NAME"], "Download")?>" class="tablebodylink" href="/bitrix/tools/form_show_file.php?rid=<?=$result_id?>&hash=<?echo $arFile["USER_FILE_HASH"]?>〈=<?=LANGUAGE_ID?>&action=download">Download</a> ] <br><br> <? endif; endif; // display field for file upload echo CForm::GetFileField( $arAnswer["ID"], $arAnswer["FIELD_WIDTH"], "FILE", 0, // maximum file size is not limited $arFile["USER_FILE_ID"], $arAnswer["FIELD_PARAM"]); ?></td> </tr> </table> <input type="submit" name="save" value="Save"> </form>
© «Bitrix24», 2001-2024