用户无法使用手机上传文件



我有一个表格,家长可以在其中上传文件(孩子完成的家庭作业(以供老师接收。 但是,我一直收到很多抱怨,说他们在使用手机时无法上传文件。当他们单击保存按钮时,没有任何反应。

事情是当我(超级管理员(和老师使用PC或手机从我们的页面上传时,它会顺利上传。

为什么父母不能上传文件,尤其是用手机上传文件。

我不知道这是编码问题还是服务器问题。

目前,我使用具有4个CPU内核,4GB DDR4 RAM,无限带宽和无限SSD空间的共享云托管。

public function upload_docs($data)
{
$this->db->where('homework_id',$data['homework_id']);
$this->db->where('student_id',$data['student_id']);
$q = $this->db->get('submit_assignment');
if ( $q->num_rows() > 0 ) 
{
$this->db->where('homework_id',$data['homework_id']);
$this->db->where('student_id',$data['student_id']);
$this->db->update('submit_assignment',$data);
} else {
$this->db->insert('submit_assignment',$data);
}
}
// public function upload_docs($data)
// {
//     if (isset($data['id']) && $data['id'] != null) {
//         $this->db->where("id", $data["id"])->update("submit_assignment", $data);
//         return $data['id'];
//     } else {
//         $this->db->insert("submit_assignment", $data);
//         return $this->db->insert_id();
//     }
// }

控制器

public function upload_docs()
{
$homework_id         = $_REQUEST['homework_id'];
$student_id          =$_REQUEST['student_id'];
$data['homework_id'] = $homework_id;
$data['student_id']  = $student_id;
$data['message']     = $_REQUEST['message'];
// $data['id']=$_POST['assigment_id'];
$is_required=$this->homework_model->check_assignment($homework_id,$student_id);
$this->form_validation->set_rules('message', $this->lang->line('message'), 'trim|required|xss_clean');
$this->form_validation->set_rules('file', $this->lang->line('attach_document'), 'trim|xss_clean|callback_handle_upload['.$is_required.']');
if ($this->form_validation->run() == FALSE) {
$msg=array(
'message'=>form_error('message'),
'file'=>form_error('file'),
);
$array = array('status' => 'fail', 'error' => $msg, 'message' => '');
}else{
if (isset($_FILES["file"]) && !empty($_FILES['file']['name'])) {
$time     = md5($_FILES["file"]['name'] . microtime());
$fileInfo = pathinfo($_FILES["file"]["name"]);
$img_name = $time . '.' . $fileInfo['extension'];           
$data['docs'] =  $img_name;
move_uploaded_file($_FILES["file"]["tmp_name"], "./uploads/homework/assignment/" . $data['docs']);
$data['file_name']=$_FILES["file"]['name'];
$this->homework_model->upload_docs($data);
}
$array = array('status' => 'success', 'error' => '', 'message' => $this->lang->line('success_message'));
}
echo json_encode($array);
}
public function handle_upload($str,$is_required)
{
$image_validate = $this->config->item('file_validate');
if (isset($_FILES["file"]) && !empty($_FILES['file']['name']) && $_FILES["file"]["size"] > 0) {
$file_type         = $_FILES["file"]['type'];
$file_size         = $_FILES["file"]["size"];
$file_name         = $_FILES["file"]["name"];
$allowed_extension = $image_validate['allowed_extension'];
$ext               = pathinfo($file_name, PATHINFO_EXTENSION);

$allowed_mime_type = $image_validate['allowed_mime_type'];
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mtype = finfo_file($finfo, $_FILES['file']['tmp_name']);
finfo_close($finfo);
if (!in_array($mtype, $allowed_mime_type)) {
$this->form_validation->set_message('handle_upload', 'File Type Not Allowed');
return false;
}
if (!in_array($ext, $allowed_extension) || !in_array($file_type, $allowed_mime_type)) {
$this->form_validation->set_message('handle_upload', 'Extension Not Allowed');
return false;
}
if ($file_size > $image_validate['upload_size']) {
$this->form_validation->set_message('handle_upload', $this->lang->line('file_size_shoud_be_less_than') . number_format($image_validate['upload_size'] / 1048576, 2) . " MB");
return false;
}
return true;
} else {
if($is_required==0){
$this->form_validation->set_message('handle_upload', 'Please choose a file to upload.');
return false;
}else{
return true;
}
}

}

视图

<td class="mailbox-date pull-right">
<a onclick="upload_docs('<?php echo $homework['id']; ?>', '<?php echo $upload_docsButton; ?>');" class="btn btn-default btn-xs"    data-toggle="tooltip"  data-original-title="<?php echo $this->lang->line('homework') . " " . $this->lang->line('assignments'); ?>">
<i class="fa fa-upload"></i></a>
<a class="btn btn-default btn-xs" onclick="evaluation('<?php echo $homework['id']; ?>','<?php echo $hw;?>');" title="" data-target="#evaluation" data-toggle="modal"  data-original-title="Evaluation">
<i class="fa fa-reorder"></i></a>    
</td>

<div class="modal fade" id="upload_docs" tabindex="-1" role="dialog" aria-labelledby="evaluation" style="padding-left: 0 !important">
<div class="modal-dialog" role="document">
<div class="modal-content modal-media-content">
<div class="modal-header modal-media-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="box-title"><?php echo $this->lang->line('homework'); ?> <?php echo $this->lang->line('assignments'); ?></h4>
</div>
<form id="upload" method="post" class="ptt10" enctype="multipart/form-data">
<div class="modal-body pt0">
<div class="row">
<input type="hidden" name="student_id" value="<?php echo $student_id; ?>">
<input type="hidden" id="homework_id"  name="homework_id">
<input type="hidden" id="assigment_id" name="assigment_id">
<div class="col-sm-12">
<div class="form-group">
<label for="pwd"><?php echo $this->lang->line('message'); ?></label>
<textarea type="text" id="assigment_message" name="message" class="form-control "></textarea>
</div> 
</div>
<div class="col-sm-12">
<div class="form-group">
<label for="pwd"><?php echo $this->lang->line('attach_document'); ?></label>
<input type="file" id="file" name="file" class="form-control filestyle">
</div>
</div>
<p id="uploaded_docs"></p>
</div>
</div>
<div class="box-footer">
<div class="" id="footer_area">
<button type="submit" class="btn btn-info pull-right" id="submit" data-loading-text="<i class='fa fa-spinner fa-spin '></i> Please wait"><?php echo $this->lang->line('save'); ?></button>
</div>

你的观点是混乱的。 首先添加表单操作,然后添加按钮表单属性,如下所示:

<button type="submit" form="upload" class="btn btn-info pull-right" id="submit" data-loading-text='SOME TEXT'> Please wait<?php echo $this->lang->line('save'); ?></button>

<form id="upload" role="form" method="post" class="ptt10" enctype="multipart/form-data" action="upload_docs">

相关内容

  • 没有找到相关文章

最新更新