function content_public_files_form_validate

7.x content.module content_public_files_form_validate($form, $form_state)
6.x content.module content_public_files_form_validate($form, $form_state)

File

modules/content/content.module, line 439

Code

function content_public_files_form_validate($form, $form_state) {

  if (isset($form_state ['values']['upload_btn']) && $form_state ['values']['upload_btn'] != "") {
    // The user is trying to upload a file.


    // Make sure there is something there.
    if (!isset($_FILES ['upload_file']) || trim($_FILES ['upload_file']['name'][0]) == '') {
      form_error('upload_file', t('Please select a file from your computer to upload.'));
      return;
    }



    // Make sure it's the correct extension.
    $original_filename = $_FILES ['upload_file']['name'][0];
    // Figure out the extension of the original filename.
    $temp = explode(".", $original_filename);
    $ext = $temp [count($temp) - 1];

    // Make sure that this extension is allowed.
    $allowed_extensions = csv_to_array(strtolower(variable_get("public_files_allowed_extensions", "css, txt, pdf, doc, docx, csv, xls, xlsx, ppt, pptx, rtf, odt, jpg, jpeg, png, gif, zip, 7z")));
    if (!in_array(strtolower($ext), $allowed_extensions)) {
      // Meaning, this extension is not allowed!
      form_error('upload_file', t("Sorry, the file's type/extension (%ext) is not allowed.  Please rename or select another file, then try again.", array("%ext" => $ext)));
      return;
    }

    // If we made it here, then there's nothing wrong and we can continue to the _submit function.


  } // upload file 


}