CodeIgniter: เกิดข้อผิดพลาดในการอัปโหลดไฟล์ Excel

ฉันกำลังพยายามอัปโหลดไฟล์ Excel ใน CodeIgniter ตามที่ฉันได้ระบุไว้ด้านล่าง แต่มีข้อความแจ้งว่าไฟล์ไม่ถูกต้อง มีปัญหาที่ซ่อนอยู่กับ CodeIgniter หรือข้อกำหนดประเภทไฟล์ของฉันหรือไม่?

$config['allowed_types'] = 'xls|xlsx';

person Alphy    schedule 23.12.2012    source แหล่งที่มา
comment
ไฟล์ของคุณชื่ออะไรกันแน่?   -  person alditis    schedule 23.12.2012
comment
ชื่อไฟล์จะแตกต่างกันไป โดยอาจเป็น abc.xlsx หรือ cds.xlsx   -  person Alphy    schedule 23.12.2012
comment
ตรวจทาน: stackoverflow.com/questions/7495407/   -  person alditis    schedule 23.12.2012


คำตอบ (7)


ฉันใช้สิ่งนี้ใน mime.php ของฉัน:

'xls'   =>  array('application/excel', 'application/vnd.ms-excel', 'application/vnd.ms-office', 'application/octet-stream', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip', 'application/x-zip', 'application/vnd.ms-excel', 'application/msword'),
'xlsx'  =>  array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip', 'application/x-zip', 'application/vnd.ms-excel', 'application/msword'),

อย่าลืมเกี่ยวกับ 'application/vnd.ms-office'

person Vladimir Kattsov    schedule 29.10.2015

เพิ่มสิ่งนี้ลงใน mimes.php ของคุณ ตรวจสอบชื่อส่วนขยาย Excel ของคุณด้วย

หรือคุณสามารถใช้ได้เช่นกัน

$config['allowed_types'] = '*';

'xlsx'  =>  array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip')
person Denmark    schedule 11.10.2013

ฉันพบวิธีแก้ปัญหานี้

'xlsx' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip', 'application/x-zip', 'application/vnd.ms-excel', 'application/msword' )

'xls' => array('application/excel', 'application/vnd.ms-excel', 'application/octet-stream'),

person Carlos Avalos    schedule 11.10.2013

วิธีแก้ปัญหาอื่น ๆ โดย joni jones การอัปโหลด ใน Codeigniter - ประเภทไฟล์ที่คุณพยายามอัปโหลดไม่ได้รับอนุญาต

หากคุณไม่ต้องการเปลี่ยนไฟล์ระบบ แค่ลองสิ่งนี้:

เปิด system/libraries/Upload.php (วิธี do_upload() บรรทัด 205) และทำสิ่งนี้:

var_dump($this->file_type);
exit();

ลองอัพโหลดไฟล์. เพิ่มประเภทไฟล์ที่คุณเห็นใน var_dump() ถึง application/config/mimes.php ตัวอย่างเล็กๆ น้อยๆ: คุณมีปัญหากับ .docx ลองเพิ่ม:

'docx' => array('application/zip', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document')

to application/config/mimes.php.

person Carlos Avalos    schedule 11.10.2013

'xls' => array('application/excel', 'application/vnd.ms-excel', 'application/octet-stream'),

'xlsx' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip', 'application/x-zip', 'application/vnd.ms-excel', 'application/msword'),
'xls' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip', 'application/x-zip', 'application/vnd.ms-excel', 'applica
    tion/msword'),

แทนที่ด้วย xls และ xlsx ประเภท mime ก่อนหน้าของคุณ ใส่โค้ดด้านบนที่สามารถใช้งานได้

xls สองเพิ่มไม่ใช่ปัญหา

'xls' => array('application/excel', 'application/vnd.ms-excel', 'application/octet-stream'), working in to the my local but not working this live sit(Production site)

'xls' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip', 'application/x-zip', 'application/vnd.ms-excel', 'applica
        tion/msword'),

มันกำลังทำงานอยู่ในไซต์การผลิตสด

ฉันกำลังวาง xls สองอันไว้ทั้งสองที่ใช้งานได้

person Raja Ram T    schedule 05.02.2014

ฉันประสบปัญหาเดียวกันกับการอัปโหลดไฟล์ CodeIgniter และเวอร์ชันของฉันของ CodeIgniter คือ 2.2.0 คุณสามารถดูคำตอบได้จาก คำตอบ< ต่อไปนี้ /ก>!!!

ขอให้โชคดี!!!

person Randika Vishman    schedule 27.08.2014

ใน config/mimes.php

เพิ่มสิ่งนี้

'xlsx'  =>  array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip'),
'xls'   =>  array('application/excel', 'application/vnd.ms-excel', 'application/msexcel'),
'ods'   =>  array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip')

และในการกำหนดค่าของคุณ

$config['allowed_types'] = 'xlsx|xls|ods';
person Abdulla Nilam    schedule 30.10.2015