图片上传后,打印出来没有任何数据,这是怎么回事?
开发环境xamp,window7点击上传后,var_dump($this->upload->data());打印出来没有任何数据,也没有提示任何错误,这是什么情况?
打印出来的结果是:
array(14) {
["file_name"]=>
string(0) ""
["file_type"]=>
string(0) ""
["file_path"]=>
string(0) ""
["full_path"]=>
string(0) ""
["raw_name"]=>
string(0) ""
["orig_name"]=>
string(0) ""
["client_name"]=>
string(0) ""
["file_ext"]=>
string(0) ""
["file_size"]=>
string(0) ""
["is_image"]=>
bool(false)
["image_width"]=>
string(0) ""
["image_height"]=>
string(0) ""
["image_type"]=>
string(0) ""
["image_size_str"]=>
string(0) ""
}
下面是代码,求各位大神帮帮小弟...
以下是test.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Test extends CI_Controller {
public function index()
{
$this->load->view('file.html');
}
public function upload(){
$this->load->library('upload');
$copnfig['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|png|jpg|jpeg';
$this->load->library('upload',$config);
$this->upload->do_upload('pic');
var_dump($this->upload->data());
}
}
?>
以下是file.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>上传测试</title>
</head>
<body>
<form action="<?php echo site_url('test/upload');?>" method="post" enctype="multipart/form-data">
<input type="file" name="pic"/>
<input type="submit" value="上传"/>
</form>
</body>
</html>
请仔细检查下你的代码。。
1. upload 库 load 了两次,第一次没带 config 参数,CI会以这个为准,第二次 load 没用了
2. $copnfig['upload_path'] 中的 copnfig 拼写错误!
3. 记得要检查下 './uploads/' 目录是否存在,是否有写入权限
4. 如果还有问题,可以用 $this->upload->display_errors() 把错误打印出来调试下 aneasystone 发表于 2015-8-5 20:44
请仔细检查下你的代码。。
1. upload 库 load 了两次,第一次没带 config 参数,CI会以这个为准,第二次 lo ...
确实是这样,我删掉了没带参数的config,现在能正常上传了,谢谢{:soso__3110130392203091378_3:}
页:
[1]