function course_search_upload_attachment
Search API
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()
- course_search_edit_course_details_form_submit in modules/
course_search/ course_search.edit.inc
File
- modules/
course_search/ course_search.edit.inc, line 354 - 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"][0];
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"][0];
// 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 = trim(substr($original_filename, 0, 30)) . ".$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($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;
}