Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php `$this->;上传->;do_upload()`在使用ajax时不起作用_Php_Jquery_Ajax_Codeigniter - Fatal编程技术网

Php `$this->;上传->;do_upload()`在使用ajax时不起作用

Php `$this->;上传->;do_upload()`在使用ajax时不起作用,php,jquery,ajax,codeigniter,Php,Jquery,Ajax,Codeigniter,我有一个项目codeigniter,我将使用ajax提交表单。我的第一个问题是$this->upload->do_upload总是错误的。我确实在寻找一些答案,但我无法完成这项工作 我尝试了这个链接来解决我的问题,但没有帮助 希望有人能帮助我。下面是我的代码 查看 <form id="form-register" enctype="mutlipart/form-data" action="" method="POST"> <div class="row"&g

我有一个项目codeigniter,我将使用ajax提交表单。我的第一个问题是
$this->upload->do_upload
总是错误的。我确实在寻找一些答案,但我无法完成这项工作

我尝试了这个链接来解决我的问题,但没有帮助

希望有人能帮助我。下面是我的代码

查看

<form id="form-register" enctype="mutlipart/form-data" action="" method="POST">
      <div class="row">
         <div class="col-md-4">
             <div class="form-group">
                  <div class="form-group form-file-upload form-file-multiple ">
                     <input type="file" class="inputFileHidden"  name="client_img" id="client_img">
                     <div class="fileinput-new thumbnail img-raised">
                             img class="img-fluid" src="<? echo base_url();?>assets/img/person.png" alt="client-img" />
                     </div>
                     <div class="input-group mt-2">
                        <span class="input-group-btn">
                           <button type="button" class="btn btn-fab btn-round btn-primary">
                               <i class="material-icons">attach_file</i>
                            </button>
                         </span>
                         <input type="text" class="form-control inputFileVisible"  placeholder="Choose client picture.." require>
                     </div>
                  </div>
               </div>
             </div>
Ajax.js

$(document).ready(function(e) {
    $(".client-save").click(function(e) {
        e.preventDefault();
        var formdata = new FormData(document.getElementById("form-register"));

        if (formdata) {
            $.ajax({
                type: "POST",
                url: "register",
                dataType: "json",
                data: formdata,
                processData: false,
                contentType: false,
                cache: false,
                success: function(response) {
                    if (response.success == true) {
                        alert(response.messages);
                    } else {
                        showNotification("top", "right", response.messages);
                    }
                }
            });
        }
    });
});
希望有人能为这一个网站我的问题。我尝试修改ajax代码,但仍然是

$this->upload->do_upload()


仍然为false。

您可以调用display\u errors()方法来帮助您进行调试,只需在返回响应的地方添加以下内容:

echo "<pre>";
   die(var_dump( $this->upload->display_errors() ));
echo "</pre>";

由于需要附加图像文件,可以尝试以下代码


也许正确拼写
enctype
属性的值会有所帮助。是的,我正在使用linux。我真的忘了chmod的目的了。非常感谢。现在出现了错误。我做了sudo chmod 777-R/opt/lampp/htdocs/project。谢谢
echo "<pre>";
   die(var_dump( $this->upload->display_errors() ));
echo "</pre>";
if (!is_dir('uploads')) {
    mkdir('./uploads', 0777, true);
}
        var formData = new FormData();
        formData.append('client_img', $('#client_img')[0].files[0]);