我收到错误:当我尝试上传任何文件时,不允许您尝试上传的文件类型.
if(!empty($_FILES['proof_of_purchase']['name'])) {
$config['upload_path'] = './uploads/invoices/';
$config['allowed_types'] = 'gif|jpg|jpeg|png|pdf|bmp';
$config['max_size'] = '3000';
$this->load->library('upload', $config);
// if there was an error, return and display it
if (!$this->upload->do_upload('proof_of_purchase'))
{
$data['error'] = $this->upload->display_errors();
$data['include'] = 'pages/classic-register';
} else {
$data['upload_data'] = $this->upload->data();
$filename = $data['upload_data']['file_name'];
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试过很多不同的文件 - 主要是gif和jpeg,每次都会得到同样的错误.
后续代码var_dump($ _ FILES); 给我:
array(1) { ["proof_of_purchase"]=> array(5) { ["name"]=> string(28) "2010-12-04_00019.jpg" ["type"]=> string(10) "image/jpeg" ["tmp_name"]=> string(19) "D:\temp\php2BAE.tmp" ["error"]=> int(0) ["size"]=> int(58054) } }
Run Code Online (Sandbox Code Playgroud)
我检查了mime配置,它包含正确的东西.例:
'jpeg' => array('image/jpeg', 'image/pjpeg'),
'jpg' => array('image/jpeg', 'image/pjpeg'), …
Run Code Online (Sandbox Code Playgroud) 我试图找出如何访问基本上多维JSON数组中的数据.
我的jQuery AJAX请求如下所示:
$("#login-form").submit(function(e) {
e.preventDefault();
$.ajax({
type: 'POST',
url: '/ajax/login',
data: 'email='+$("#email").val()+'&password='+$("#password").val(),
success: function(data){
// FIRE ALERT HERE
alert(data.firstname);
},
dataType: 'json'
});
});
Run Code Online (Sandbox Code Playgroud)
这就是我要回来的.用户帐户详细信息,以及他们针对其帐户的产品列表.
{
"logged_in":true,
"firstname":"Joe",
"surname":"Bloggs",
"Full_name":"Joe Bloggs",
"email":"email@website.com",
"phone":"+123456789",
"website":"",
"age":"26-35",
"street":"1 Street Ave",
"city":"Townland",
"state":"NA",
"postcode":"1234",
"country":"Australia",
"products":2,
"0":{
"product_no":"1087",
"customer":"2",
"bought_from":"1",
"date_of_purchase":"2011-04-08",
"method":"instore",
"invoice":"0",
"current":"1"
},
"1":{
"product_no":"24",
"customer":"2",
"bought_from":"1",
"date_of_purchase":"2011-04-08",
"method":"instore",
"invoice":"0",
"current":"1"
}
}
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,我正在警告第一个名字,这很好.我可以通过使用data.key访问第一维中的所有内容,但我不知道如何我需要索引下一个维度.显然我想以某种方式展示每个产品.
建议是最受欢迎的.