php 如何使用 Codeigniter 上传图片文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15719477/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to Upload Image files Using Codeigniter?
提问by JayKandari
How to Upload Image files Using Codeigniter? Codeigniter's Upload class Library
如何使用 Codeigniter 上传图片文件? Codeigniter 的上传类库
gives no hint for how to upload a image using simple form and upload the image to it's images folder which is present in the root directory...
没有提示如何使用简单的形式上传图像并将图像上传到根目录中的图像文件夹...
Thanks in advance..
提前致谢..
回答by It worked yesterday.
Here is an example. Hope this would help you :)
这是一个例子。希望这会帮助你:)
in your controller. lets say upload.php
在您的控制器中。让我们说upload.php
public function upload() {
if($this->input->post('upload')) {
$config['upload_path'] = APPPATH . 'your upload folder name here/';
$config['file_name'] = filename_here;
$config['overwrite'] = TRUE;
$config["allowed_types"] = 'jpg|jpeg|png|gif';
$config["max_size"] = 1024;
$config["max_width"] = 400;
$config["max_height"] = 400;
$this->load->library('upload', $config);
if(!$this->upload->do_upload()) {
$this->data['error'] = $this->upload->display_errors();
} else {
//success
}
}
}
Then in your view
那么在你看来
<?php echo form_open_multipart('upload'); ?>
<?php echo form_upload('userfile'); ?><br />
<?php echo form_submit('upload', 'Upload');?>
<?php echo form_close(); ?>