本文整理汇总了PHP中file_add函数的典型用法代码示例。如果您正苦于以下问题:PHP file_add函数的具体用法?PHP file_add怎么用?PHP file_add使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了file_add函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: file_process_posted_files_for_bug
/**
* Processes the post files from a form by adding them to the specified
* issue.
*
* @param int $p_bug_id The bug id.
* @param array $p_files The array of files, if null, then do nothing.
*/
function file_process_posted_files_for_bug($p_bug_id, $p_files)
{
if ($p_files === null) {
return;
}
$t_files = helper_array_transpose($p_files);
foreach ($t_files as $t_file) {
if (!empty($t_file['name'])) {
file_add($p_bug_id, $t_file, 'bug');
}
}
}
示例2: reportBug
function reportBug($p_event, $p_bug_data)
{
$p_var_name = 'ufile';
if (isset($_POST[$p_var_name])) {
$f = $_POST[$p_var_name][0];
$h = "data:image/png;base64,";
if (substr($f, 0, strlen($h)) == $h) {
$data = base64_decode(substr($f, strlen($h)));
$fn = tempnam("/tmp", "CLPBRD");
file_put_contents($fn, $data);
chmod($fn, 0777);
$t_result = array();
$pi = pathinfo($fn);
$t_result[0]['name'] = $pi['filename'] . ".png";
$t_result[0]['type'] = "image/png";
$t_result[0]['size'] = strlen($data);
$t_result[0]['tmp_name'] = $fn;
$t_result[0]['error'] = 0;
file_add($p_bug_data->id, $t_result[0]);
}
}
}
示例3: process
//.........这里部分代码省略.........
$t_custom_fields[++$i] = new stdClass();
}
switch ($reader->localName) {
default:
$field = $reader->localName;
$reader->read();
$t_custom_fields[$i]->{$field} = $reader->value;
}
}
}
break;
case 'bugnotes':
// store bug notes
$i = -1;
$depth_bn = $reader->depth;
while ($reader->read() && ($reader->depth > $depth_bn || $reader->nodeType != XMLReader::END_ELEMENT)) {
if ($reader->nodeType == XMLReader::ELEMENT) {
if ($reader->localName == 'bugnote') {
$t_bugnotes[++$i] = new stdClass();
}
switch ($reader->localName) {
case 'reporter':
$t_old_id = $reader->getAttribute('id');
$reader->read();
$t_bugnotes[$i]->reporter_id = $this->get_user_id($reader->value, $userId);
break;
case 'view_state':
$t_old_id = $reader->getAttribute('id');
$reader->read();
$t_bugnotes[$i]->private = $reader->value == VS_PRIVATE ? true : false;
break;
default:
$field = $reader->localName;
$reader->read();
$t_bugnotes[$i]->{$field} = $reader->value;
}
}
}
break;
case 'attachments':
// store attachments
$i = -1;
$depth_att = $reader->depth;
while ($reader->read() && ($reader->depth > $depth_att || $reader->nodeType != XMLReader::END_ELEMENT)) {
if ($reader->nodeType == XMLReader::ELEMENT) {
if ($reader->localName == 'attachment') {
$t_attachments[++$i] = new stdClass();
}
switch ($reader->localName) {
default:
$field = $reader->localName;
$reader->read();
$t_attachments[$i]->{$field} = $reader->value;
}
}
}
break;
default:
$field = $reader->localName;
//echo "using default handler for field: $field\n";
$reader->read();
$this->newbug_->{$field} = $reader->value;
}
}
}
// now save the new bug
$this->new_id_ = $this->newbug_->create();
// add custom fields
if ($this->new_id_ > 0 && is_array($t_custom_fields) && count($t_custom_fields) > 0) {
foreach ($t_custom_fields as $t_custom_field) {
$t_custom_field_id = custom_field_get_id_from_name($t_custom_field->name);
if (custom_field_ensure_exists($t_custom_field_id) && custom_field_is_linked($t_custom_field_id, $t_project_id)) {
custom_field_set_value($t_custom_field->id, $this->new_id_, $t_custom_field->value);
} else {
error_parameters($t_custom_field->name, $t_custom_field_id);
trigger_error(ERROR_CUSTOM_FIELD_NOT_LINKED_TO_PROJECT, ERROR);
}
}
}
// add bugnotes
if ($this->new_id_ > 0 && is_array($t_bugnotes) && count($t_bugnotes) > 0) {
foreach ($t_bugnotes as $t_bugnote) {
bugnote_add($this->new_id_, $t_bugnote->note, $t_bugnote->time_tracking, $t_bugnote->private, $t_bugnote->note_type, $t_bugnote->note_attr, $t_bugnote->reporter_id, false, $t_bugnote->date_submitted, $t_bugnote->last_modified, true);
}
}
// add attachments
if ($this->new_id_ > 0 && is_array($t_attachments) && count($t_attachments) > 0) {
foreach ($t_attachments as $t_attachment) {
// Create a temporary file in the temporary files directory using sys_get_temp_dir()
$temp_file_name = tempnam(sys_get_temp_dir(), 'MantisImport');
file_put_contents($temp_file_name, base64_decode($t_attachment->content));
$file_data = array('name' => $t_attachment->filename, 'type' => $t_attachment->file_type, 'tmp_name' => $temp_file_name, 'size' => filesize($temp_file_name), 'error' => UPLOAD_ERR_OK);
// unfortunately we have no clue who has added the attachment (this could only be fetched from history -> feel free to implement this)
// also I have no clue where description should come from...
file_add($this->new_id_, $file_data, 'bug', $t_attachment->title, $p_desc = '', $p_user_id = null, $t_attachment->date_added, true);
unlink($temp_file_name);
}
}
//echo "\nnew bug: $this->new_id_\n";
}
示例4: auth_get_current_user_id
if ($t_bug_data->handler_id == NO_USER && $t_bug_data->status >= config_get('bug_resolved_status_threshold')) {
$t_bug_data->handler_id = auth_get_current_user_id();
}
# Create the bug
$t_bug_id = $t_bug_data->create();
# Mark the added issue as visited so that it appears on the last visited list.
last_visited_issue($t_bug_id);
# Handle the file upload
for ($i = 0; $i < count($f_files); $i++) {
if (!empty($f_files['name'][$i])) {
$t_file['name'] = $f_files['name'][$i];
$t_file['tmp_name'] = $f_files['tmp_name'][$i];
$t_file['type'] = $f_files['type'][$i];
$t_file['error'] = $f_files['error'][$i];
$t_file['size'] = $f_files['size'][$i];
file_add($t_bug_id, $t_file, 'bug');
}
}
# Handle custom field submission
foreach ($t_related_custom_field_ids as $t_id) {
# Do not set custom field value if user has no write access
if (!custom_field_has_write_access($t_id, $t_bug_id)) {
continue;
}
$t_def = custom_field_get_definition($t_id);
if (!custom_field_set_value($t_id, $t_bug_id, gpc_get_custom_field("custom_field_{$t_id}", $t_def['type'], $t_def['default_value']), false)) {
error_parameters(lang_get_defaulted(custom_field_get_field($t_id, 'name')));
trigger_error(ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR);
}
}
$f_master_bug_id = gpc_get_int('m_id', 0);
示例5: addAttachment
public function addAttachment($bugID, $name, $str)
{
if (MANTIS_LOCAL) {
$tmpFile = tempnam(sys_get_temp_dir(), 'feedback');
file_put_contents($tmpFile, $str);
file_add($bugID, $tmpFile, $name, 'text/plain');
unlink($tmpFile);
} else {
$this->client->mc_issue_attachment_add(MANTIS_USER, MANTIS_PWD, $bugID, $name, 'text/plain', $str);
}
}
示例6: require_api
require_api('lang_api.php');
require_api('print_api.php');
require_api('utility_api.php');
form_security_validate('proj_doc_add');
# Check if project documentation feature is enabled.
if (OFF == config_get('enable_project_documentation')) {
access_denied();
}
access_ensure_project_level(config_get('upload_project_file_threshold'));
$f_title = gpc_get_string('title');
$f_description = gpc_get_string('description');
$f_file = gpc_get_file('file');
if (is_blank($f_title)) {
error_parameters(lang_get('title'));
trigger_error(ERROR_EMPTY_FIELD, ERROR);
}
file_add(0, $f_file, 'project', $f_title, $f_description);
form_security_purge('proj_doc_add');
$t_redirect_url = 'proj_doc_page.php';
html_page_top(null, $t_redirect_url);
?>
<br />
<div align="center">
<?php
echo lang_get('operation_successful') . '<br />';
print_bracket_link($t_redirect_url, lang_get('proceed'));
?>
</div>
<?php
html_page_bottom();
示例7: custom_field_get_definition
$t_def = custom_field_get_definition($t_id);
if ($t_def['require_report'] && gpc_get_custom_field("custom_field_{$t_id}", $t_def['type'], '') == '') {
error_parameters(lang_get_defaulted(custom_field_get_field($t_id, 'name')));
trigger_error(ERROR_EMPTY_FIELD, ERROR);
}
if (!custom_field_validate($t_id, gpc_get_custom_field("custom_field_{$t_id}", $t_def['type'], $t_def['default_value']))) {
error_parameters(lang_get_defaulted(custom_field_get_field($t_id, 'name')));
trigger_error(ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR);
}
}
# Create the bug
$t_bug_id = bug_create($t_bug_data);
# Handle the file upload
if (!is_blank($f_file['tmp_name']) && 0 < $f_file['size']) {
$f_file_error = isset($f_file['error']) ? $f_file['error'] : 0;
file_add($t_bug_id, $f_file['tmp_name'], $f_file['name'], $f_file['type'], 'bug', $f_file_error);
}
# Handle custom field submission
foreach ($t_related_custom_field_ids as $t_id) {
# Do not set custom field value if user has no write access.
if (!custom_field_has_write_access($t_id, $t_bug_id)) {
continue;
}
$t_def = custom_field_get_definition($t_id);
if (!custom_field_set_value($t_id, $t_bug_id, gpc_get_custom_field("custom_field_{$t_id}", $t_def['type'], $t_def['default_value']))) {
error_parameters(lang_get_defaulted(custom_field_get_field($t_id, 'name')));
trigger_error(ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR);
}
}
$f_master_bug_id = gpc_get_int('m_id', 0);
$f_rel_type = gpc_get_int('rel_type', -1);
示例8: addfile
function addfile()
{
header("Content-type: text/html; charset=utf-8");
$type = v('type');
$filename = v('filename');
$filecat = v('filecat');
$file_type = explode('.', $_FILES["file"]["name"]);
$save_name = time() . '.' . $file_type[1];
$path = AROOT . "static/upload/" . $save_name;
$data_path = "static/upload/" . $save_name;
if (file_exists($path)) {
echo "<script>";
echo "alert('上传出错,存在同名文件!')";
echo "</script>";
} else {
if ($_FILES["file"]["error"] == 0) {
move_uploaded_file($_FILES["file"]["tmp_name"], $path);
$array = array($filecat, $filename, $data_path);
$result = file_add($array);
} else {
echo "<script>";
echo "alert('上传出错!')";
echo "</script>";
}
}
echo "<script>";
echo "window.location.href = '" . c($site_url) . "?c=backedit&a=lists&item=" . $type . "' ";
echo "</script>";
}
示例9: config_get
$t_core_path = config_get('core_path');
require_once $t_core_path . 'file_api.php';
# Check if project documentation feature is enabled.
if (OFF == config_get('enable_project_documentation')) {
access_denied();
}
access_ensure_project_level(config_get('upload_project_file_threshold'));
$f_title = gpc_get_string('title');
$f_description = gpc_get_string('description');
$f_file = gpc_get_file('file');
if (is_blank($f_title)) {
error_parameters(lang_get('title'));
trigger_error(ERROR_EMPTY_FIELD, ERROR);
}
$f_file_error = isset($f_file['error']) ? $f_file['error'] : 0;
file_add(0, $f_file['tmp_name'], $f_file['name'], $f_file['type'], 'project', $f_file_error, $f_title, $f_description);
$t_redirect_url = 'proj_doc_page.php';
html_page_top1();
html_meta_redirect($t_redirect_url);
html_page_top2();
?>
<br />
<div align="center">
<?php
echo lang_get('operation_successful') . '<br />';
print_bracket_link($t_redirect_url, lang_get('proceed'));
?>
</div>
<?php
html_page_bottom1(__FILE__);
示例10: save_bug
function save_bug($p_project_id, $p_user_id)
{
require 'ProfileAcraExt.php';
$t_project_id = $p_project_id;
global $g_cache_current_user_id;
$g_cache_current_user_id = $p_user_id;
$t_bug_data = new BugData();
$t_bug_data->project_id = $t_project_id;
$t_bug_data->reporter_id = $p_user_id;
$t_bug_data->build = gpc_get_string('APP_VERSION_CODE', '');
$t_bug_data->platform = "Android";
$t_bug_data->os = gpc_get_string('ANDROID_VERSION', '');
//gpc_get_string( 'os', '' );
$t_os_build = gpc_get_string('BUILD', '');
if (preg_match('/DISPLAY\\s*=\\s*(.*)/', $t_os_build, $t_match)) {
var_dump($t_match);
$t_os_build = $t_match[1];
} else {
$t_os_build = gpc_get_string('ANDROID_VERSION', '');
}
$t_bug_data->os_build = $t_os_build;
//gpc_get_string( 'os_build', '' );
$t_bug_data->version = gpc_get_string('APP_VERSION_NAME', '');
$t_bug_data->profile_id = profile_create_unique(ALL_USERS, $t_bug_data->platform, $t_bug_data->os, $t_bug_data->os_build, "");
$t_bug_data->handler_id = gpc_get_int('handler_id', 0);
$t_bug_data->view_state = gpc_get_int('view_state', config_get('default_bug_view_status', 'VS_PRIVATE', 'acra_reporter'));
$t_bug_data->category_id = $this->get_category_id($p_project_id);
//gpc_get_int( 'category_id', 0 );
$t_bug_data->reproducibility = 10;
//gpc_get_int( 'reproducibility', config_get( 'default_bug_reproducibility' ) );
$t_bug_data->severity = CRASH;
//gpc_get_int( 'severity', config_get( 'default_bug_severity' ) );
$t_bug_data->priority = HIGH;
//gpc_get_int( 'priority', config_get( 'default_bug_priority' ) );
$t_bug_data->projection = gpc_get_int('projection', config_get('default_bug_projection'));
$t_bug_data->eta = gpc_get_int('eta', config_get('default_bug_eta'));
$t_bug_data->resolution = OPEN;
//gpc_get_string('resolution', config_get( 'default_bug_resolution' ) );
$t_bug_data->status = NEW_;
//gpc_get_string( 'status', config_get( 'bug_submit_status' ) );
$t_bug_data->description = gpc_get_string('STACK_TRACE');
//gpc_get_string( 'description' );
$t_bug_data->summary = get_bug_summary_by_version(gpc_get_string('APP_VERSION_NAME', ''), $t_bug_data->description, $t_project_id);
$t_bug_data->steps_to_reproduce = gpc_get_string('LOGCAT', "");
$t_bug_data->additional_information = gpc_get_string('CRASH_CONFIGURATION', "");
$t_bug_data->due_date = gpc_get_string('USER_CRASH_DATE', '');
if (is_blank($t_bug_data->due_date)) {
$t_bug_data->due_date = date_get_null();
}
$f_files = gpc_get_file('ufile', null);
/** @todo (thraxisp) Note that this always returns a structure */
$f_report_stay = gpc_get_bool('report_stay', false);
$f_copy_notes_from_parent = gpc_get_bool('copy_notes_from_parent', false);
helper_call_custom_function('issue_create_validate', array($t_bug_data));
# Validate the custom fields before adding the bug.
$t_related_custom_field_ids = custom_field_get_linked_ids($t_bug_data->project_id);
foreach ($t_related_custom_field_ids as $t_id) {
$t_def = custom_field_get_definition($t_id);
# Produce an error if the field is required but wasn't posted
if (!gpc_isset_custom_field($t_id, $t_def['type']) && $t_def['require_report']) {
error_parameters(lang_get_defaulted(custom_field_get_field($t_id, 'name')));
trigger_error(ERROR_EMPTY_FIELD, ERROR);
}
if (!custom_field_validate($t_id, gpc_get_custom_field("custom_field_{$t_id}", $t_def['type'], NULL))) {
error_parameters(lang_get_defaulted(custom_field_get_field($t_id, 'name')));
trigger_error(ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR);
}
}
# Allow plugins to pre-process bug data
$t_bug_data = event_signal('EVENT_REPORT_BUG_DATA', $t_bug_data);
# Ensure that resolved bugs have a handler
if ($t_bug_data->handler_id == NO_USER && $t_bug_data->status >= config_get('bug_resolved_status_threshold')) {
$t_bug_data->handler_id = $this->get_user_id();
}
# Create the bug
$t_bug_id = $t_bug_data->create();
# Mark the added issue as visited so that it appears on the last visited list.
last_visited_issue($t_bug_id);
# Handle the file upload
if ($f_files != null) {
$t_files = helper_array_transpose($f_files);
if ($t_files != null) {
foreach ($t_files as $t_file) {
if (!empty($t_file['name'])) {
file_add($t_bug_id, $t_file, 'bug');
}
}
}
}
# Handle custom field submission
foreach ($t_related_custom_field_ids as $t_id) {
# Do not set custom field value if user has no write access
if (!custom_field_has_write_access($t_id, $t_bug_id)) {
continue;
}
$t_def = custom_field_get_definition($t_id);
if (!custom_field_set_value($t_id, $t_bug_id, gpc_get_custom_field("custom_field_{$t_id}", $t_def['type'], $t_def['default_value']), false)) {
error_parameters(lang_get_defaulted(custom_field_get_field($t_id, 'name')));
trigger_error(ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR);
}
//.........这里部分代码省略.........
示例11: form_security_validate
form_security_validate( 'bug_file_add' );
$t_bug = bug_get( $f_bug_id, true );
if( $t_bug->project_id != helper_get_current_project() ) {
# in case the current project is not the same project of the bug we are viewing...
# ... override the current project. This to avoid problems with categories and handlers lists etc.
$g_project_override = $t_bug->project_id;
}
if ( !file_allow_bug_upload( $f_bug_id ) ) {
access_denied();
}
access_ensure_bug_level( config_get( 'upload_bug_file_threshold' ), $f_bug_id );
file_add( $f_bug_id, $f_file, 'bug' );
form_security_purge( 'bug_file_add' );
# Determine which view page to redirect back to.
$t_redirect_url = string_get_bug_view_url( $f_bug_id );
html_page_top( null, $t_redirect_url );
?>
<br />
<div>
<?php
echo lang_get( 'operation_successful' ) . '<br />';
print_bracket_link( $t_redirect_url, lang_get( 'proceed' ) );
?>
</div>
示例12: strlen
$t_result[0]['type'] = "image/png";
$t_result[0]['size'] = strlen($data);
$t_result[0]['tmp_name'] = $fn;
$t_result[0]['error'] = 0;
}
} else {
if (func_num_args() > 1) {
# check for a default passed in (allowing null)
$t_result = $p_default;
} else {
error_parameters($p_var_name);
trigger_error(ERROR_GPC_VAR_NOT_FOUND, ERROR);
}
}
}
return $t_result;
}
$f_bug_id = gpc_get_int('bug_id', -1);
$f_files = gpc_get_fileCustom('pic', -1);
if ($f_bug_id == -1 && $f_files == -1) {
# _POST/_FILES does not seem to get populated if you exceed size limit so check if bug_id is -1
trigger_error(ERROR_FILE_TOO_BIG, ERROR);
}
$t_bug = bug_get($f_bug_id, true);
if (!file_allow_bug_upload($f_bug_id)) {
access_denied();
}
access_ensure_bug_level(config_get('upload_bug_file_threshold'), $f_bug_id);
file_add($f_bug_id, $f_files, 'bug', '', '', 1);
#Message de succès d'envoi
exit_status(plugin_lang_get('file_was_uploaded_successfuly'));