上载路径在CodeIgniter 3中似乎无效

6qftjkof  于 2022-12-07  发布在  其他
关注(0)|答案(2)|浏览(108)

我有一个CodeIgniter项目假定2nd_c,另一个CodeIgniter项目假定1st_c。我想将文件和图像上载到1st_c项目,但它引发路径错误“The upload path does not appear be valid”我已加载“upload”库,下面是我的代码

$config=array();

                    $config['upload_path'] = '../assets/uploads/jobs';

                    $config['allowed_types'] = 'gif|jpg|jpeg|png';

                    $config['overwrite']     = false;

                    $config['max_size']      = 3000;

                    $config['remove_spaces'] = true;

                    $config['max_filename']   = 10;

                    $config['file_ext_tolower'] = true;

                    $this->upload->initialize($config);
                    
                    if($this->upload->do_upload('pic')){

                    $udata = array('upload_data' => $this->upload->data());                

                    $jobimage = $udata['upload_data']['file_name'];            

                    $data['j_image'] = $jobimage;     

                   }else{

                       $errors = $this->upload->display_errors();

                       echo "<pre>"; print_r($errors); echo "</pre>";

                       exit;

                    }

“../assets/uploads/jobs”这是我的1st_c项目,它在本地主机上工作正常,但在服务器上抛出错误。我已经尝试了“FCPATH”,但没有运气。

5t7ly7z5

5t7ly7z51#

处理配置项文件夹时,请使用APPPATHbase_url()

$file_path = realpath(APPPATH . '../assets/uploads/jobs');

$file_path = base_url().'/assets/uploads/jobs');

文件夹结构应为

Application
assets
    uploads
        jobs
system
index.php
gfttwv5a

gfttwv5a2#

$upload_path = "Test_folder/Temp_folder";
              public function upload($upload_path,$name){
                  $config['upload_path'] = $upload_path;
                  $config['allowed_types'] = 'pdf';
                  $config['max_size'] = 0;
                  $config['file_name'] = $name;

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

                  if (!$this->upload->do_upload('file'))
                  {
                      return "true";
                  }
                  else{
                      $file_data = $this->upload->data();
                      $file_name = $file_data['file_name'];
                      return $file_name;
                  }
                }

相关问题