jobberBase custom development and support


Code School

Restrict Uploaded Files to Doc Types

Hi, to those who are wanting to limit the file types that applicants send. Here is a short mod

on page_apply.php find:

if ($_FILES['apply_cv'] && $_FILES['apply_cv']['size'] >= MAX_CV_SIZE)
    $errors['apply_cv'] = $translations['apply']['cv_error'];

add below it:

//check if file-type is acceptable
if ($_FILES['apply_cv'] && (($_FILES['apply_cv']['type'] != "text/plain") AND ($_FILES['apply_cv']['type'] != "application/pdf") AND ($_FILES['apply_cv']['type'] != "application/msword") AND ($_FILES['apply_cv']['type'] != "application/rtf") AND ($_FILES['apply_cv']['type'] != "application/vnd.oasis.opendocument.text")))
    $errors['apply_attach'] = $translations['apply']['attach_invalid'];

Open translations.ini in /_includes folder and add a line on the [apply] section:

attach_invalid = "Your attachment is invalid. We only accept *.doc, *.docx, *.pdf and *.txt"

Open job-details.tpl in /_templates folder and add:

<td valign="top"><label for="apply_cv">{$translations.apply.cv_label}:</label></td>
<input type="file" name="apply_cv" id="apply_cv" {if $smarty.session.apply_errors.apply_attach}class="error"{/if}/>
<span class="validation-error">{if $smarty.session.apply_errors.apply_cv OR $smarty.session.apply_errors.apply_attach}<img src="{$BASE_URL}img/icon-delete.png" alt="" />{/if}</span>
<div class="suggestion">{$translations.apply.cv_info}</div>

Leave a Response