php - 上传文件不起作用。可能是一些权限问题
问题描述
我想知道这么久,文件上传部分不起作用。我用谷歌搜索了很多来解决这个问题,我发现上传目录的文件权限可能存在问题,但我不明白如何用我的代码实现相同的功能。以下是代码。
$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" ;
}
预先感谢..
解决方案
从代码的第一部分开始,变量 $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) ;
}
关于上传问题,您能否提供您收到的任何错误消息,以便其他人更好地帮助。
如果您的浏览器上没有显示任何内容,您可以检查 httpd 日志以获取信息,或者在您的 php 脚本顶部设置以下内容:
ini_set('display_errors', 0);
这将覆盖您在 php.ini 中的设置以强制显示错误。
此外,如果您可以通过 SSH 访问您的服务器,请在“FCCPATH”中运行以下命令:
ls -alhR
这将递归地列出目录中的所有内容,因此如果您担心显示目录中的其他文件,您只需要显示“上传”的输出及其内容。
这将显示文件和文件夹权限,以便我们查看您当前的文件权限设置,以进一步帮助您。
推荐阅读
- functional-programming - 说服 Agda 递归函数正在终止
- javascript - 在对象数组中查找最接近的数字
- matlab - Matlab:如何添加反转缓冲区堆栈的方法?
- reactjs - 创建一组条目时将唯一变量传递给 onClick 函数
- amazon-web-services - 为什么我需要通过预签名 url 上传到 s3 的存储桶策略?
- c# - 高 DPI 缩放 WinForms 面板控件不缩放
- rest - 软件开发接口术语之间的区别:API、Web API、REST API、Web 服务、SOAP 服务
- mysql - 如何在 cpanel 中设置连接 mysql 数据库的节点 js 服务器
- python - 有效年份范围的正则表达式
- math - 如何在ckeditor中将路径写入本地MathJax库?