function course_search_upload_attachment

7.x course_search.edit.inc course_search_upload_attachment($course_id, $subject_id, $course_num)
6.x course_search.edit.inc course_search_upload_attachment($course_id, $subject_id, $course_num)
4.x course_search.edit.inc course_search_upload_attachment($course_id, $subject_id, $course_num)
5.x course_search.edit.inc course_search_upload_attachment($course_id, $subject_id, $course_num)
1 call to course_search_upload_attachment()

File

modules/course_search/course_search.edit.inc, line 290
This file contains functions relating to editing the course info, like rotation schedule and syllabus

Code

function course_search_upload_attachment($course_id, $subject_id, $course_num) {

  // If any files were attached, go ahead and upload them.
  $datetime = date("_y-j-m_g-i-sa", time());


  $tmp_filename = $_FILES ["syllabus"]["tmp_name"];
  if (trim($tmp_filename) != "") {
    // Meaning, yes, a file was uploaded.
    $suffix = $datetime;
    // Create the new filename, based on the id's its been assigned.
    $original_filename = $_FILES ["syllabus"]["name"];
    // replace problem characters...
    $original_filename = str_replace("'", "", $original_filename);
    $original_filename = str_replace('"', '', $original_filename);
    $original_filename = str_replace(",", "", $original_filename);

    $temp = explode("\.", $original_filename);
    $ext = $temp [count($temp) - 1]; // get the original extension.
    $new_filename = $original_filename . ".$suffix.$ext";


    // Does the directory/files/syllabi exist?
    // If not, we will create it.
    $files_path = $GLOBALS ["fp_system_settings"]["file_system_path"];

    if (!is_dir("$files_path/custom/files/syllabi")) {
      if (!mkdir("$files_path/custom/files/syllabi")) {
        return FALSE;
      }
    }

    // Try to copy...
    if (!copy($tmp_filename, "$files_path/custom/files/syllabi/$new_filename")) {
      return FALSE;
    }

    // If we are here, then there is success!  We should update the
    // table with the new filename, which is $new_filename.
    // delete the existing entry, if any.

    // We need to unlink any existing syllabus file...
    if ($file_details = course_search_get_course_syllabus_details($subject_id, $course_num, $course_id)) {
      $filename = $file_details ["filename"];
      if (!unlink("$files_path/custom/files/syllabi/$filename")) {
        fp_add_message(t("Unable to delete existing file:") . " $filename");
      }
    }

    db_query("DELETE FROM course_syllabi
              WHERE course_id = '?' ", $course_id);

    // Okay, now add the new entry.
    db_query("INSERT INTO course_syllabi
            (course_id, course_perm_id, filename, posted)
            values ('?','?" . "_?','?', '?' )", $course_id, $subject_id, $course_num, $new_filename, time());



  }

  return TRUE;

}