Fixing document name when uploading a file related to #3778

skala
Julio Montoya 15 years ago
parent 6627a2b3a6
commit ba4a83b77e
  1. 5
      main/inc/ajax/document.ajax.php
  2. 11
      main/inc/lib/database.lib.php
  3. 25
      main/inc/lib/document.lib.php

@ -28,8 +28,9 @@ switch($action) {
if (!empty($_FILES)) {
require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php';
$result = DocumentManager::upload_document($_FILES, $_POST['curdirpath'], '', '', 0, 'overwrite', false, false);
$file = $_FILES['file'];
$file = $_FILES['file'];
$result = DocumentManager::upload_document($_FILES, $_POST['curdirpath'], $file['name'], '', 0, 'overwrite', false, false);
$json = array();
$json['name'] = Display::url(api_htmlentities($file['name']), api_htmlentities($result['url']), array('target'=>'_blank'));
$json['type'] = api_htmlentities($file['type']);

@ -1057,7 +1057,7 @@ class Database {
* Experimental useful database insert
* @todo lot of stuff to do here
*/
public static function insert($table_name, $attributes , $show_query = false) {
public static function insert($table_name, $attributes, $show_query = false) {
if (empty($attributes) || empty($table_name)) {
return false;
}
@ -1192,7 +1192,7 @@ class Database {
return $return_value;
}
private function parse_where_conditions($coditions){
private function parse_where_conditions($coditions) {
return self::parse_conditions(array('where'=>$coditions));
}
@ -1213,9 +1213,12 @@ class Database {
/**
* Experimental useful database update
* @param string table name use Database::get_main_table
* @param array array with values to updates, keys are the fields in the database: Example: $params['name'] = 'Julio'; $params['lastname'] = 'Montoya';
* @param array where conditions i.e array('id = ?' =>'4')
* @todo lot of stuff to do here
*/
public static function update($table_name, $attributes, $where_conditions = array()) {
public static function update($table_name, $attributes, $where_conditions = array(), $show_query = false) {
if (!empty($table_name) && !empty($attributes)) {
$update_sql = '';
@ -1233,7 +1236,7 @@ class Database {
//Parsing and cleaning the where conditions
$where_return = self::parse_where_conditions($where_conditions);
$sql = "UPDATE $table_name SET $update_sql $where_return ";
//echo $sql; exit;
if ($show_query) { echo $sql; echo '<br />'; }
$result = self::query($sql);
$affected_rows = self::affected_rows();
return $affected_rows;

@ -2109,26 +2109,25 @@ return 'application/octet-stream';
$base_work_dir = $sys_course_path.$course_dir;
if (isset($files['file'])) {
$upload_ok = process_uploaded_file($files['file'], $show_output);
$upload_ok = process_uploaded_file($files['file'], $show_output);
if ($upload_ok) {
// File got on the server without problems, now process it
$new_path = handle_uploaded_document($course_info, $files['file'], $base_work_dir, $path, api_get_user_id(), api_get_group_id(), null, $max_filled_space, $unzip, $if_exists, $show_output);
if ($new_path) {
$new_comment = isset($title) ? trim($comment) : '';
$new_title = isset($title) ? trim($title) : '';
$docid = DocumentManager::get_document_id($course_info, $new_path);
if ($new_path && ($new_comment || $new_title)) {
if (!empty($docid)) {
$table_document = Database::get_course_table(TABLE_DOCUMENT);
$ct = '';
if ($new_comment) $ct .= ", comment='$new_comment'";
if ($new_title) $ct .= ", title='$new_title'";
Database::query("UPDATE $table_document SET ".substr($ct, 1)." WHERE id = $docid");
if (!empty($docid)) {
$table_document = Database::get_course_table(TABLE_DOCUMENT);
$params = array();
if (!empty($title)) {
$params['title'] = trim($title);
} else {
$params['title'] = $files['file']['name'];
}
if (!empty($comment)) {
$params['comment'] = trim($comment);
}
Database::update($table_document, $params, array('id = ?' =>$docid));
}
// Showing message when sending zip files

Loading…
Cancel
Save