codeigniter图像和pdf上传失败

时间:2016-01-20 15:51:04

标签: php codeigniter

我想接受表格上的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; upload_image&#39;功能第一。它完全像我预期的那样畏缩。 我之后调用upload_pdf时会发生错误。它表明&#39; pdf&#39;上传不允许输入。 好像我不能覆盖&#39; image_upload&#39;中的配置。使用&#39; pdf_upload&#39;中的那个。

这是错误。使用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"" }

1 个答案:

答案 0 :(得分:0)

$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();
}
相关问题