Skip to content

Commit

Permalink
* file_api.php
Browse files Browse the repository at this point in the history
  (file_add): new function to add a file to a bug


git-svn-id: http://mantisbt.svn.sourceforge.net/svnroot/mantisbt/trunk@1495 f5dc347c-c33d-0410-90a0-b07cc1902cb9
  • Loading branch information
Julian Fitzell committed Sep 16, 2002
1 parent 9a59e6e commit ed3d542
Showing 1 changed file with 61 additions and 1 deletion.
62 changes: 61 additions & 1 deletion core/file_api.php
Expand Up @@ -6,7 +6,7 @@
# See the README and LICENSE files for details

# --------------------------------------------------------
# $Id: file_api.php,v 1.9 2002-09-16 04:16:59 jfitzell Exp $
# $Id: file_api.php,v 1.10 2002-09-16 10:05:46 jfitzell Exp $
# --------------------------------------------------------

###########################################################################
Expand Down Expand Up @@ -193,5 +193,65 @@ function file_type_check( $p_file_name ) {
}
return false;
}
# --------------------
function file_add( $p_bug_id, $p_tmp_file, $p_file_name, $p_file_type='' ) {
$c_bug_id = db_prepare_int( $p_bug_id );
$c_tmp_file = db_prepare_string( $p_tmp_file );
$c_file_name = db_prepare_string( $p_file_name );
$c_file_type = db_prepare_string( $p_file_type );

if ( !file_type_check( $p_file_name ) ) {
trigger_error( ERROR_FILE_NOT_ALLOWED, ERROR );
} else if ( is_uploaded_file( $p_tmp_file ) ) {
$t_project_id = bug_get_field( $p_bug_id, 'project_id' );

# grab the file path
$t_file_path = project_get_field( $t_project_id, 'file_path' );

$t_bug_id = str_pad( $p_bug_id, '0', 7, STR_PAD_LEFT );

# prepare variables for insertion
$t_new_file_name = $t_bug_id.'-'.$c_file_name;
$t_file_size = filesize( $p_tmp_file );

$t_method = config_get( 'file_upload_method' );
$t_bug_file_table = config_get( 'mantis_bug_file_table' );

switch ( $t_method ) {
case FTP:
case DISK:
if ( !file_exists( $t_file_path . $t_new_file_name ) ) {
if ( FTP == $t_method ) {
$conn_id = file_ftp_connect();
file_ftp_put ( $conn_id, $t_new_file_name, $p_tmp_file );
file_ftp_disconnect ( $conn_id );
}

umask( 0333 ); # make read only
copy( $p_tmp_file, $t_file_path . $t_new_file_name );

$query = "INSERT INTO $t_bug_file_table
(id, bug_id, title, description, diskfile, filename, folder, filesize, file_type, date_added, content)
VALUES
(null, $c_bug_id, '', '', '$t_file_path$t_new_file_name', '$t_new_file_name', '$t_file_path', $t_file_size, '$c_file_type', NOW(), '')";
db_query( $query );
} else {
trigger_error( ERROR_FILE_DUPLICATE, ERROR );
}
break;
case DATABASE:
$t_content = db_prepare_string( fread ( fopen( $p_tmp_file, 'rb' ), $t_file_size ) );
$query = "INSERT INTO $t_bug_file_table
(id, bug_id, title, description, diskfile, filename, folder, filesize, file_type, date_added, content)
VALUES
(null, $c_bug_id, '', '', '$t_file_path$t_new_file_name', '$t_new_file_name', '$t_file_path', $t_file_size, '$c_file_type', NOW(), '$t_content')";
db_query( $query );
break;
}

# log new bug
history_log_event_special( $p_bug_id, FILE_ADDED, $p_file_name );
}

}
?>

0 comments on commit ed3d542

Please sign in to comment.