小编Sta*_*see的帖子

CodeIgniter - 文件上传需要验证

我有2个文本字段和1个文件上传都是必需的.当我只需要文本字段时,一切都有效,但是当我需要文件上传时,验证错误仍然表示需要一个文件,即使我选择了一个文件.谁知道我做错了什么?提前谢谢了.

//视图

<?php echo form_open_multipart('add'); ?>

<fieldset>
    <input type="text" name="name" /><br>
    <input type="text" name="code" /><br>
    <input type="file" name="userfile" /><br><br>
    <input type="submit"value="Add" />
</fieldset>

<?php echo form_close(); ?>
Run Code Online (Sandbox Code Playgroud)

//控制器

public function add() {

    $this->form_validation->set_rules('name', 'Name', 'required');
    $this->form_validation->set_rules('code', 'Code', 'required');
    //$this->form_validation->set_rules('userfile', 'Document', 'required');
    //when the above line is active the upload does not go through

    if ($this->form_validation->run() == FALSE) {

        $data['page_view'] = $this->page_view;
        $data['page_title'] = $this->page_title;
        $this->load->view('template', $data);
    }
    else
    {
        $this->load->library('upload');

        if (!empty($_FILES['userfile']['name']))
        {
            $config['upload_path'] = './uploads/';
            $config['allowed_types'] = 'gif|jpg|png|jpeg';     

            $this->upload->initialize($config); …
Run Code Online (Sandbox Code Playgroud)

php validation codeigniter

32
推荐指数
4
解决办法
9万
查看次数

CodeIgniter Active记录多个"where"和"or"语句

我有以下Active Record查询.

//Example 1
public function info($school, $class, $student, $keyword)
{
    $this->db->where('school.id', $school);
    $this->db->where('class.id', $class);
    $this->db->where('student.id', $student);

    $this->db->or_where('school.description', $keyword);
    $this->db->or_where('class.description', $keyword);
    $this->db->or_where('student.description', $keyword); 

    return $this->db->get('info')->result();
}
Run Code Online (Sandbox Code Playgroud)

我想对底部3"or_where"语句进行分组,以便它们包含在前3个"where"语句中.我想出的解决方案是......

//Example 2
public function info($school, $class, $student, $keyword) 
{
    $this->db->where('school.description', $keyword);
    $this->db->where('school.id', $school);
    $this->db->where('class.id', $class);
    $this->db->where('student.id', $student);

    $this->db->or_where('class.description', $keyword);
    $this->db->where('school.id', $school);
    $this->db->where('class.id', $class);
    $this->db->where('student.id', $student);

    $this->db->or_where('student.description', $keyword); 
    $this->db->where('school.id', $school);
    $this->db->where('class.id', $class);
    $this->db->where('student.id', $student);

    return $this->db->get('info')->result();
}
Run Code Online (Sandbox Code Playgroud)

这工作正常,但有没有办法在不重复代码的情况下执行此操作?

php codeigniter

8
推荐指数
1
解决办法
2万
查看次数

Laravel和Dropbox WebAuth:“会话中缺少CSRF令牌”

我正在使用Laravel 5.0,并尝试使用Dropbox进行授权。我大致遵循以下示例:http : //dropbox.github.io/dropbox-sdk-php/api-docs/v1.1.x/class-Dropbox.WebAuth.html

当我去/开始。我被重定向到Dropbox并单击“允许”,但是当我被重定向回/ finish时,我在会话中不断收到Missing CSRF令牌。有人有什么想法吗?我读过这$_SESSION在Laravel中不起作用,但是我不确定该怎么做。

这是我正在使用的代码:

public function start()
{   
    $authorizeUrl = $this->getWebAuth()->start();

    return redirect()->away($authorizeUrl);
}

public function finish()
{       
    $test = $this->getWebAuth()->finish($_GET);

    dd($test);
}

private function getWebAuth()
{   
    $appKey = 'key';
    $appSecret = 'secret';
    $appName = 'name';
    $appRedirect = 'http://example.com/finish';

    $appInfo = new Dropbox\AppInfo($appKey, $appSecret);
    $csrfTokenStore = new Dropbox\ArrayEntryStore($_SESSION, 'dropbox-auth-csrf-token');
    $webAuth = new Dropbox\WebAuth($appInfo, $appName, $appRedirect, $csrfTokenStore);

    return $webAuth;
}
Run Code Online (Sandbox Code Playgroud)

更新1:

好的,所以我尝试与Laravel SocialiteDropbox Socialite提供程序一起使用。我将代码更改为以下代码,但按/ start时出现错误。Driver [dropbox] not supported。我对说明的 …

php dropbox laravel-5

5
推荐指数
1
解决办法
803
查看次数

Codeigniter Bootstrap分页

我正在使用CodeIgniter和Twitter Bootstrap创建一个Web应用程序.我在网上找到了一个资源,其中包含$ config设置列表,可以正确设置分页链接的样式.有没有办法将它存储在库中并将其加载到控制器中,所以我不必每次都输入它?

codeigniter

4
推荐指数
1
解决办法
1万
查看次数

Moment.js仅在上周内

我正在使用moment.js"timeAgo"来显示一些日期.但是如果日期在上周内,我只想使用moment.js.(7天前)在那之后我只想正常显示日期.例如:(2010年6月20日)而不是(3年前).

我有使用此代码的默认值.任何帮助都会很棒.

var date = moment.unix(<?php echo $date; ?>).fromNow();
$("#date").append(date);
Run Code Online (Sandbox Code Playgroud)

javascript momentjs

4
推荐指数
1
解决办法
2549
查看次数

CodeIgniter活动记录比较日期

我在数据库中有一个列,其日期存储为mm/dd/yyyy.我需要获取日期大于某个日期的所有行.(例如,2013年1月1日之后的任何日期).如何使用活动记录执行此操作?

我试过了

$this->db->select('DATE_FORMAT(date, '%mm/%dd/%Y') as mydate');
$this->db->where('mydate >','01/01/2013');
Run Code Online (Sandbox Code Playgroud)

codeigniter

4
推荐指数
1
解决办法
5068
查看次数

CodeIgniter - 删除文件,路径问题

我的根目录中有3个文件夹,"应用程序","系统"和"上传".在application/controllers/mycontroller.php中,我有这行代码.

delete_files("../../uploads/$file_name");
Run Code Online (Sandbox Code Playgroud)

该文件没有被删除,我尝试了一些路径选项,如../和../../../任何想法?谢谢.

codeigniter

2
推荐指数
1
解决办法
2万
查看次数

打印时,仅加载print.css而不是styles.css

打印时有没有办法只使用print.css而不是styles.css?我觉得90%的print.css正在撤消styles.css中的样式.

css

0
推荐指数
1
解决办法
438
查看次数

标签 统计

codeigniter ×5

php ×3

css ×1

dropbox ×1

javascript ×1

laravel-5 ×1

momentjs ×1

validation ×1