codeigniter upload not working on linux

2020-05-03 11:34发布

问题:

I'm developing an application using CodeIgniter 2.2.0. In my app, users will be able to upload pdf files to the server.

I'm using uploadifive.js on the interface, I also have a controller that first of all creates the directory structure where the file is going to be stored.

Everything works fine on my localhost (W7 and Apache) directory is created, file name is encrypted and so on. The problem occurs when trying to upload a file on my production server, Ubuntu 12. Directories are being created but no file is uploaded.

I have read more than twenty posts but couldn't find a solution.

Here there are several lines of the uploader code, I'm not an expert in Ubuntu nor in Linux, so it must be a misconfiguration issue. Who knows?

if(!empty($_POST['type_folder'])){          

    $upload_file = FCPATH . '/application/files/'.$_POST['number_identification'].'/'.$_POST['type_folder'].'/COD_'.$_POST['id_agreement'].'/'.sha1($_POST['type_folder']."_".$_POST['id_agreement']."_".$_POST['number_identification']).'.pdf';

    if (file_exists($upload_file)) {
        @unlink($upload_file);
    }

    $file_name = sha1($_POST['type_folder']."_".$_POST['id_agreement']."_".$_POST['number_identification']);
    $final_upload_folder = $upload_sub_sub_folder_by_service;

}                   

if ($status != "error")
{
    $config['upload_path'] = $final_upload_folder;          
    $config['allowed_types'] = 'pdf';
    $config['max_size'] = 1024 * 1024 * 4;
    $config['file_name'] = $file_name;          

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

    if (!$this->upload->do_upload($file_element_name))
    {
        $status = 'error';
        $msg = $this->upload->display_errors('', '');

    }
    else
    {
        //echo "<pre>"; Print_r($this->upload->data()); echo "</pre>";
        $data = $this->upload->data();
        ...
    }

回答1:

Check your folder's permissions. If you create your folders programmatically with php you can set your permissions right after with http://php.net/manual/en/function.chmod.php.

ex.

chmod("/path/to/somedir", 0755);