Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.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
Codeigniter文件上载失败_Codeigniter_Upload - Fatal编程技术网

Codeigniter文件上载失败

Codeigniter文件上载失败,codeigniter,upload,Codeigniter,Upload,我有一个允许上传文件的表格。它可以添加到数据库中,但不会将文件保存到指定的文件夹中。我的视图和模型代码如下(我的控制器只需检查文件是否已设置,然后继续上载) 视图: 我从表单中得到了正确的文件名,我上传的文件大小和扩展名都正确。我在本地主机上工作,所以文件夹权限很好,但由于某些原因,它就是不起作用。最近我在另一个项目上做了类似的事情,但我似乎找不到问题所在 任何帮助都将不胜感激 编辑: 如果我打印$data,我会得到以下信息 Array ( [file_name] => 08f8ce288

我有一个允许上传文件的表格。它可以添加到数据库中,但不会将文件保存到指定的文件夹中。我的视图和模型代码如下(我的控制器只需检查文件是否已设置,然后继续上载)

视图:

我从表单中得到了正确的文件名,我上传的文件大小和扩展名都正确。我在本地主机上工作,所以文件夹权限很好,但由于某些原因,它就是不起作用。最近我在另一个项目上做了类似的事情,但我似乎找不到问题所在

任何帮助都将不胜感激

编辑:

如果我打印$data,我会得到以下信息

Array ( [file_name] => 08f8ce288e45207735bdb3f0c3139a0a.txt [file_type] => text/plain [file_path] => C:/wamp/www/marine/certificate_files/ [full_path] => C:/wamp/www/marine/files/08f8ce288e45207735bdb3f0c3139a0a.txt [raw_name] => 08f8ce288e45207735bdb3f0c3139a0a [orig_name] => license.txt [client_name] => license.txt [file_ext] => .txt [file_size] => 2.44 [is_image] => [image_width] => [image_height] => [image_type] => [image_size_str] => ) 

{"status":"error","msg":"Something went wrong when saving the file, please try again."}

我建议您使用Uploadify

这是一个非常容易使用的jQuery插件,有着令人惊叹的文档。我从开始编写代码起就开始使用它,从来没有遇到过任何问题


这样,您可以轻松解决两个项目的问题。

看起来
$This->saveCertificate()
失败了;我们能看看吗?您从中返回了什么吗?正如stormdrain所说,
$this->saveCertificate()
失败了。虽然似乎发生的是
$this->upload->do\u upload($file\u element\u name)
失败,因此
$file\u id
从未设置,因此
$this->saveCertificate()
失败。您的
$msg
变量也被覆盖,因此您没有看到从
$this->upload->display_errors()返回的错误;如果删除第二条If/else语句(
If($file\u id){…
),您应该会看到一个错误,说明文件未上载的原因。“”。
function uploadOffshoreMedical($uid)
{   
    $status = "";
    $msg = "";
    $file_element_name = 'offshore_medical_certificate';
    $certificate_name = 'Offshore Medical';
    if ($status != "error")
    {
        $config['upload_path'] = './certificate_files/';
        $config['allowed_types'] = 'pdf|doc|docx|txt|png|gif|jpg|jpeg|';
        $config['max_size']  = 1024 * 8;
        $config['encrypt_name'] = TRUE;

        $this->load->library('upload', $config);

        if (!$this->upload->do_upload($file_element_name))
        {
            $status = 'error';
            $msg = $this->upload->display_errors();
        }
        else
        {
            $data = $this->upload->data();
            $file_id = $this->saveCertificate($uid, $data['raw_name'], $data['file_ext'], $certificate_name);
        }
        if($file_id)
        {
            $status = "success";
            $msg = "File successfully uploaded";
        }
        else
        {
            unlink($data['full_path']);
            $status = "error";
            $msg = "Something went wrong when saving the file, please try again.";
        }

        @unlink($_FILES[$file_element_name]);
    }   
    echo json_encode(array('status' => $status, 'msg' => $msg));
}
Array ( [file_name] => 08f8ce288e45207735bdb3f0c3139a0a.txt [file_type] => text/plain [file_path] => C:/wamp/www/marine/certificate_files/ [full_path] => C:/wamp/www/marine/files/08f8ce288e45207735bdb3f0c3139a0a.txt [raw_name] => 08f8ce288e45207735bdb3f0c3139a0a [orig_name] => license.txt [client_name] => license.txt [file_ext] => .txt [file_size] => 2.44 [is_image] => [image_width] => [image_height] => [image_type] => [image_size_str] => ) 

{"status":"error","msg":"Something went wrong when saving the file, please try again."}