มีใครใช้ฟังก์ชั่น mime_content_type ใน php5.2 ได้ปรกติบ้างครับ กับไฟล์ .zip .อื่นๆที่ไม่ใช่ .jpg .txt .gif .png
ผมใช้ codeigniter 2.1.1 แล้วใช้ controller ตัวนี้
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class testup extends CI_Controller {
function __construct() {
parent::__construct();
}// __construct
function index() {
$this->load->helper( array( 'form' ) );
// render form
echo '<!DOCTYPE html><html><head><title></title></head><body>';
echo form_open_multipart();
echo form_hidden( 'name', 'value' );
echo form_upload( 'file' );
echo form_submit( 'btn', 'Upload' );
echo form_close();
// start upload
if ( $_POST && isset( $_FILES['file']['name'] ) && $_FILES['file']['name'] != null ) {
// debug
echo 'file type from $_FILES: '.$_FILES['file']['type'].'<br />';
//
$config['upload_path'] = './';
$config['allowed_types'] = 'jpg|png|gif|jpeg|zip';
$this->load->library( 'upload', $config );
if ( ! $this->upload->do_upload( 'file' ) ) {
echo 'file type from CI upload->file_type: '.$this->upload->file_type.'<br />';
echo $this->upload->display_errors();
} else {
$filedata = $this->upload->data();
echo '<pre>';
print_r( $filedata );
echo '</pre>';
sleep(1);
// done, now delete file
if ( file_exists( $filedata['full_path'] ) ) {
unlink( $filedata['full_path'] );
}
}
}
//
echo '</body></html>';
}
}
// EOF
ไฟล์ testup.php ใน application/controller
ทำการทดสอบอัพโหลดไฟล์ ปรากฏว่า php5.3 ทำงานปกติทุกอย่าง
ส่วน php5.2 บน hosting มันกลับ error The filetype you are attempting to upload is not allowed.