代码点火器图像和 PDF 上传失败


codeigniter image and pdf upload fail

我想接受表单上的pdf和图像。我像这样编写名为"Myfileupload"的自定义类。

<?php 
    defined('BASEPATH') OR eixt('No direct script acccess allowed');
    //myfileupload library
    class Myfileupload{
        var $image_name;
        var $pdf_name;
        function __construct() {
            $this->CI = & get_instance();
        }
        function upload_image($image) {
            $config['upload_path'] = './upload/image';
            $config['allowed_types'] = 'jpeg|gif|jpg|png';
            $config['max_size'] = 0;
            $config['max_width']  = 0;
            $config['max_height']  = 0;
            $config['encrypt_name'] = TRUE;
            $this->CI->load->library('upload', $config);
            $temp = $this->CI->upload->do_upload($image);
            $this->image_name = $this->CI->upload->data('file_name');
            return $temp;
        }
        function getImageName() {
            return $this->image_name;
        }
        function upload_pdf($pdf_name) {
            $config['upload_path'] = './upload/pdf';
            $config['allowed_types'] = 'pdf';
            $config['max_size'] = 0;
            $config['encrypt_name'] = TRUE;
            $this->CI->load->library('upload', $config);
            $temp = $this->CI->upload->do_upload($pdf_name);
            $this->pdf_name = $this->CI->upload->data('file_name');
        }
        function getPdfName() {
            return $this->pdf_name;
        }
    }
?>

在控制器中,我首先调用"upload_image"函数。它完全按照我的预期。当我之后调用upload_pdf时会发生错误。它显示不允许上传"pdf"类型。似乎我无法用"pdf_upload"中的配置覆盖"image_upload"中的配置。

这是错误。结果使用 var_dump() 进行修改;

PDF UPLOAD!
The filetype you are attempting to upload is not allowed.

array(14) { ["file_name"]=> string(94) "IP address သိရင္ ဘယ္လို hack လို႔ရႏိုင္သလဲ.pdf" ["file_type"]=> string(15) "application/pdf" ["file_path"]=> string(48) "/opt/lampp/htdocs/mm-bookstore.com/upload/image/" ["full_path"]=> string(142) "/opt/lampp/htdocs/mm-bookstore.com/upload/image/IP address သိရင္ ဘယ္လို hack လို႔ရႏိုင္သလဲ.pdf" ["raw_name"]=> string(90) "IP address သိရင္ ဘယ္လို hack လို႔ရႏိုင္သလဲ" ["orig_name"]=> string(14) "kali_linux.png" ["client_name"]=> string(94) "IP address သိရင္ ဘယ္လို hack လို႔ရႏိုင္သလဲ.pdf" ["file_ext"]=> string(4) ".pdf" ["file_size"]=> int(90637) ["is_image"]=> bool(false) ["image_width"]=> int(800) ["image_height"]=> int(557) ["image_type"]=> string(3) "png" ["image_size_str"]=> string(24) "width="800" height="557"" }
$CI =& get_instance();
header("Access-Control-Allow-Origin: *"); 
header('Access-Control-Allow-Methods: GET, POST');  
$config['upload_path'] = path;
$config['allowed_types'] = 'exe|psd|pdf|xls|ppt|php|rar|php4|php3|js|swf|Xhtml|zip|mid|midi|mp2|mp3|wav|bmp|gif|jpg|jpeg|png|html|htm|txt|rtf|mpeg|mpg|avi|doc|docx|xlsx';
$this->load->helper('form');
$this->load->library('upload',$config);
$this->upload->initialize($config);
$this->upload->set_allowed_types('*');
if($this->upload->do_upload('file_name'))
{
$upload_data = $this->upload->data();
}