Я пытаюсь отправить некоторые значения в таблицу с изображением, но когда я пытаюсь загрузить имя файла, сохраненное в таблице, но изображение не перемещается в каталог. Я проверил разрешение каталога. но все равно не повезло.
функция:
function add_multiple_choice_question($quiz_id) {
if (sizeof($this->input->post('options')) != $this->input->post('number_of_options')) {
return false;
}
foreach ($this->input->post('options') as $option) {
if ($option == "") {
return false;
}
}
if (sizeof($this->input->post('correct_answers')) == 0) {
$correct_answers = [""];
} else {
$correct_answers = $this->input->post('correct_answers');
}
$data['quiz_id'] = $quiz_id;
$data['title'] = html_escape($this->input->post('title'));
$data['number_of_options'] = html_escape($this->input->post('number_of_options'));
$data['type'] = 'multiple_choice';
$data['options'] = json_encode($this->input->post('options'));
$data['correct_answers'] = json_encode($correct_answers);
if (!file_exists('uploads/quiz_image')) {
mkdir('uploads/quiz_image', 0777, true);
}
if ($_FILES['quiz_image']['name'] == "") {
$data['quiz_image'] = 'category-thumbnail.png';
} else {
$data['quiz_image'] = md5(rand(10000000, 20000000)) . '.jpg';
move_uploaded_file($_FILES['quiz_image']['tmp_name'], 'uploads/quiz_image/' . $data['quiz_image']);
}
$this->db->insert('question', $data);
return true; }
Невозможно переместить файл в каталог
Форма
<form action="<?php echo site_url('admin/quiz_questions/'.$param2.'/add'); ?>" enctype="multipart/form-data" method="post" id = 'mcq_form'>
<input type="hidden" name="question_type" value="mcq">
<div class="form-group">
<label for="title"><?php echo get_phrase('question_title'); ?></label>
<input class="form-control" type="text" name="title" id="title" required>
</div>
<div class="form-group">
<label for="title"><?php echo get_phrase('quiz_image'); ?></label>
<div class="input-group">
<div class="custom-file">
<input type="file" class="custom-file-input" name="quiz_image" onchange="changeTitleOfImageUploader(this)" accept="image/*">
<label class="custom-file-label ellipsis" for=""><?php echo get_phrase('choose_file'); ?></label>
</div>
</div>
</div>
<div class="form-group" id='multiple_choice_question'>
<label for="number_of_options"><?php echo get_phrase('number_of_options'); ?></label>
<div class="input-group">
<input type="number" class="form-control" name="number_of_options" id="number_of_options" data-validate="required" data-message-required="Value Required" min="0">
<div class="input-group-append" style="padding: 0px"><button type="button" class="btn btn-secondary btn-sm pull-right" name="button" onclick="showOptions(jQuery('#number_of_options').val())" style="border-radius: 0px;"><i class="fa fa-check"></i></button></div>
</div>
</div>
<div class="text-center">
<button class = "btn btn-success" id = "submitButton" type="button" name="button" data-dismiss="modal"><?php echo get_phrase('submit'); ?></button>
</div>
Приложение использует скрипт, но у меня нет опыта работы с ним.
<script type="text/javascript">
function showOptions(number_of_options){
$.ajax({
type: "POST",
url: "<?php echo site_url('admin/manage_multiple_choices_options'); ?>",
data: {number_of_options : number_of_options},
success: function(response){
jQuery('.options').remove();
jQuery('#multiple_choice_question').after(response);
}
});
}
$('#submitButton').click( function(event) {
$.ajax({
url: '<?php echo site_url('admin/quiz_questions/'.$param2.'/add'); ?>',
type: 'post',
data: $('form#mcq_form').serialize(),
success: function(response) {
if (response == 1) {
success_notify('<?php echo get_phrase('question_has_been_added'); ?>');
}else {
error_notify('<?php echo get_phrase('no_options_can_be_blank_and_there_has_to_be_atleast_one_answer'); ?>');
}
}
});
showLargeModal('<?php echo site_url('modal/popup/quiz_questions/'.$param2); ?>', '<?php echo get_phrase('manage_quiz_questions'); ?>');
});
</script>
Контроллер
public function quiz_questions($quiz_id = "", $action = "", $question_id = "") {
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
$quiz_details = $this->crud_model->get_lessons('lesson', $quiz_id)->row_array();
if ($action == 'add') {
$response = $this->crud_model->add_quiz_questions($quiz_id);
echo $response;
}
elseif ($action == 'edit') {
$response = $this->crud_model->update_quiz_questions($question_id);
echo $response;
}
elseif ($action == 'delete') {
$response = $this->crud_model->delete_quiz_question($question_id);
$this->session->set_flashdata('flash_message', get_phrase('question_has_been_deleted'));
redirect(site_url('admin/course_form/course_edit/'.$quiz_details['course_id']));
}
}
Я слишком много искал, перепробовал все трюки, но не повезло.