由于某些原因,此代码块在我的本地计算机上工作,但当我将其上载到GoDaddy服务器时,它不工作,它会告诉我"不允许您尝试上载的文件类型。"只有当我尝试上载csv和xlsx文件时才会发生这种情况,png和jpgs工作没有问题。
$filename = "classlist_".date("YmdHis").".csv";
$config['upload_path'] = APPPATH. '../uploads/';
$config['allowed_types'] = 'xlsx|xls|jpg|png|csv';
$config['max_size'] = '1000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
if (!$this->upload->do_upload())
{
print_r($this->upload);
echo "error<br/>".$this->upload->display_errors();
exit;
}
else
{
exit;
这是针对特定文件类型的服务器配置问题。这意味着在mimes.php
文件的$mimes
变量中找不到服务器为xlsx
提供的文件类型。文件mimes.php
位于application/config/mimes.php
中。只需打印$_FILES
变量并添加您在$mimes变量中看到的mime即可。
另一种方法是在.htaccess文件中强制使用这些mimes:
AddType application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx
AddType application/excel xls
AddType text/x-comma-separated-values csv