<?php
defined('BASEPATH')`enter code here` OR exit('No direct script access allowed');
class Upload extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
}
function index()
{
$this->load->view('upload_form', array('error' => ' '));
}
function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('Upload', $config);
if (! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
}
}
?>
Q
如何上传笨路径
-1
A
回答
0
使用这个库上传...它易于使用
http://demo.codesamplez.com/codeigniter/file-upload-demo
查看
<form action="" method="POST" enctype="multipart/form-data" >
Select File To Upload:<br />
<input type="file" name="userfile" multiple="multiple" />
<input type="submit" name="submit" value="Upload" class="btn btn-success" />
</form>
{if isset($uploaded_file)}
{foreach from=$uploaded_file key=name item=value}
{$name} : {$value}
<br />
{/foreach}
{/if}
控制器
/**
* the demo for file upload tutorial on codesamplez.com
* @return view
*/
public function file_upload_demo()
{
try
{
if($this->input->post("submit")){
$this->load->library("app/uploader");
$this->uploader->do_upload();
}
return $this->view();
}
catch(Exception $err)
{
log_message("error",$err->getMessage());
return show_error($err->getMessage());
}
}
组件
/**
* Description of uploader
*
* @author Rana
*/
class Uploader {
var $config;
public function __construct() {
$this->ci =& get_instance();
$this->config = array(
'upload_path' => dirname($_SERVER["SCRIPT_FILENAME"])."/files/",
'upload_url' => base_url()."files/",
'allowed_types' => "gif|jpg|png|jpeg|pdf|doc|xml",
'overwrite' => TRUE,
'max_size' => "1000KB",
'max_height' => "768",
'max_width' => "1024"
);
}
public function do_upload(){
$this->remove_dir($this->config["upload_path"], false);
$this->ci->load->library('upload', $this->config);
if($this->ci->upload->do_upload())
{
$this->ci->data['status']->message = "File Uploaded Successfully";
$this->ci->data['status']->success = TRUE;
$this->ci->data["uploaded_file"] = $this->ci->upload->data();
}
else
{
$this->ci->data['status']->message = $this->ci->upload->display_errors();
$this->ci->data['status']->success = FALSE;
}
}
function remove_dir($dir, $DeleteMe) {
if(!$dh = @opendir($dir)) return;
while (false !== ($obj = readdir($dh))) {
if($obj=='.' || $obj=='..') continue;
if ([email protected]($dir.'/'.$obj)) $this->remove_dir($dir.'/'.$obj, true);
}
closedir($dh);
if ($DeleteMe){
@rmdir($dir);
}
}
}
0
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
if (! $this->upload->do_upload('image name'))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
0
从您的代码,您的文件将在上传文件夹这是你的根目录下上传。 $config['upload_path'] = './uploads/';
这是您上传的文件存储的地方。 你做一个目录上传那里应用程序文件夹是。 如果你想要你的当前代码。
您需要上传图片的目标文件夹。在CodeIgniter安装的根目录创建一个名为uploads的文件夹,并将其文件权限设置为777. 默认情况下,上传例程期望文件来自名为userfile的表单字段。 从file uploading class
相关问题
- 1. 为什么上传路径无效? (笨)
- 2. 如何从笨路径
- 3. 笨URL路径
- 4. 笨文件路径
- 5. 笨路径错误
- 6. 笨设置上传路径进行安装文件夹
- 7. 上传路径似乎并没有有效的笨
- 8. 笨图片上传和路径数据库
- 9. 笨上传多个文件的路径不同的数据库
- 10. 如何上传图像笨
- 11. 如何上传图像笨
- 12. 如何更改froala上传路径wysiwyg
- 13. 上传插件 - 如何覆盖路径?
- 14. 笨路径功能定义
- 15. 如何更改jquery文件上传的默认上传路径
- 16. plupload变量上传路径?
- 17. 图片上传路径
- 18. Codeigniter无效上传路径
- 19. 文件上传路径
- 20. MVC3图片上传路径
- 21. Jqgrid文件上传路径
- 22. 上传笨
- 23. S3上传笨
- 24. 笨如何上传图片连接表
- 25. 如何在Weebly上找到上传文件的路径?
- 26. 如何在ubuntu服务器上设置gwt上传的路径
- 27. PHP上的FTP上传路径
- 28. 笨上传目录
- 29. 笨上传图片
- 30. 笨上传问题
问题不是CELAR .. –
哪里是形象的名字? –
$ this-> upload-> do_upload('userfile')和Upload to change upload –