上传文件不起作用。可能是某些权限问题

时间:2018-05-23 07:10:18

标签: php apache

我想知道这么长时间,文件上传部分不起作用。我谷歌解决这个问题,我发现上传目录可能存在文件权限问题,但我无法理解如何使用我的代码实现相同的功能。以下是代码。

                 $tech_file_path = FCPATH . "uploads/" .  $tech_file_name ;
                 $sci_file_path = FCPATH . "uploads/" .  $sci_file_name ;

                 $tech_just_pdf_info = exec("pdfinfo " . $tech_file_path) ;
                 $tech_just_pdf_info = preg_replace('/\s+/', '', $tech_just_pdf_info);
                 $tech_pdf_version_array = explode(":",$tech_just_pdf_info) ;
                 $tech_pdf_version = 1.6;
                 //$tech_pdf_version = $tech_pdf_version_array[1];


                 $sci_just_pdf_info = exec("pdfinfo " . $sci_file_path) ;
                 $sci_just_pdf_info = preg_replace('/\s+/', '', $sci_just_pdf_info);
                 $sci_pdf_version_array = explode(":",$sci_just_pdf_info) ;
                 $sci_pdf_version = 1.6;
                 //$sci_pdf_version = $sci_pdf_version_array[1];


                 if($tech_pdf_version > 1.4)
                 {
                     // Convert PDF version to 1.4

                     shell_exec("mv " . $tech_file_path. " " . FCPATH . "uploads/temp.pdf");
                     $command1 = "/usr/bin/gs -sDEVICE=pdfwrite -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -o "  . $tech_file_path . " " .  FCPATH . "uploads/temp.pdf" ;

                     $pdf_cmd_result1 = shell_exec($command1) ;

                 }

                 if($sci_pdf_version > 1.4)
                 {
                     shell_exec("mv " . $sci_file_path. " " . FCPATH . "uploads/temp.pdf");
                     $command2 = "/usr/bin/gs -sDEVICE=pdfwrite -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -o " . $sci_file_path . " " .  FCPATH . "uploads/temp.pdf" ;

                     $pdf_cmd_result2 = shell_exec($command2) ;
                 }

文件路径和大小等

 {
    // attachemets tech and scientific_justification
      $config['upload_path']          = '../hctopses/uploads/';           
      $config['allowed_types']        = 'pdf';
      $config['max_size']             = 5120; // max size in KB
      $config['file_name']            = "tech_just" .  $this->session->userdata('proposal_id') . ".pdf";
      $config['overwrite']            = TRUE ;


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

      $err_msg = "" ;
      $success_msg = "" ;

      if (isset($_FILES['tech_justification']) && is_uploaded_file($_FILES['tech_justification']['tmp_name']))
      {
        $config['file_name']  = "tech_just" .  $this->session->userdata('proposal_id') . ".pdf";  /////

          $this->upload->initialize($config);  ///////
          if( ! $this->upload->do_upload('tech_justification'))
          {
                  $error = array('error' => $this->upload->display_errors());
                  $err_msg = "<b> Error </b> uploading Tech Just : " . implode($error, " ");
                  //$this->load->view('upload_form', $error);
          }
          else
          {
                  //$data = array('upload_data' => $this->upload->data());
                  //echo implode($this->upload->data(), " ");
                  $success_msg =  "<b>Success 1 :</b> Tech Just File Uploaded Successfully." ;
                  //$this->load->view('upload_success', $data);
          }
      }else{
          $success_msg =  "<b>Success 1 :</b> Tech Just File kept as it is Successfully." ;
      }


      if (isset($_FILES['sci_justification']) && is_uploaded_file($_FILES['sci_justification']['tmp_name']))
      {
          $config['file_name']  = "sci_just" .  $this->session->userdata('proposal_id') . ".pdf";

          $this->upload->initialize($config);
          if ( ! $this->upload->do_upload('sci_justification'))
          {
                  $error = array('error' => $this->upload->display_errors());
                  $err_msg = $err_msg . "\n <b> Error </b>uploading Sci Just : " . implode($error, " ");
                  //$this->load->view('upload_form', $error);
          }
          else
          {
                  //$data = array('upload_data' => $this->upload->data());
                  //echo implode($this->upload->data(), " ");
                  $success_msg =  $success_msg . "\n <b>Success 2 :</b> Sci Just File Uploaded Successfully." ;
                  //$this->load->view('upload_success', $data);
          }
      }else{
          $success_msg =  $success_msg . "\n <b>Success 2 :</b> Sci Just File Kept as it is Successfully." ;
      }


        if($err_msg != "")
        {
            echo $err_msg ;
        }else{
            echo $success_msg ;
        }

     //echo "Save step five Called" ;
}

提前感谢..

1 个答案:

答案 0 :(得分:0)

从代码的第一部分开始,变量$ sci_pdf_version不会更新,因此每次都会运行以下两个if语句。

             $sci_pdf_version = 1.6;
             //$sci_pdf_version = $sci_pdf_version_array[1];


             if($tech_pdf_version > 1.4)
             {
                 // Convert PDF version to 1.4

                 shell_exec("mv " . $tech_file_path. " " . FCPATH . "uploads/temp.pdf");
                 $command1 = "/usr/bin/gs -sDEVICE=pdfwrite -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -o "  . $tech_file_path . " " .  FCPATH . "uploads/temp.pdf" ;

                 $pdf_cmd_result1 = shell_exec($command1) ;

             }

             if($sci_pdf_version > 1.4)
             {
                 shell_exec("mv " . $sci_file_path. " " . FCPATH . "uploads/temp.pdf");
                 $command2 = "/usr/bin/gs -sDEVICE=pdfwrite -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -o " . $sci_file_path . " " .  FCPATH . "uploads/temp.pdf" ;

                 $pdf_cmd_result2 = shell_exec($command2) ;
             }

关于上传问题,您是否可以提供收到的任何错误消息,以便其他人提供更好的帮助。

如果浏览器上没有显示任何内容,或者在php脚本的顶部设置以下内容,您可以查看httpd日志以获取信息:

ini_set('display_errors', 0);

这将覆盖php.ini中的设置以强制显示错误。

此外,如果您具有对服务器的SSH访问权限,请在&#34; FCCPATH&#34;中运行以下内容:

ls -alhR

这将以递归方式列出目录中的所有内容,因此您只需显示&#34;上传&#34;的输出。如果您担心在目录中显示其他文件,则会显示其内容。

这将显示文件和文件夹权限,以便我们可以查看您当前的文件权限设置为进一步为您提供帮助。