Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 代码点火器积垢应用程序:缩略图图像不上传。接收数据库错误,因为空_Php_Codeigniter_Codeigniter 2 - Fatal编程技术网

Php 代码点火器积垢应用程序:缩略图图像不上传。接收数据库错误,因为空

Php 代码点火器积垢应用程序:缩略图图像不上传。接收数据库错误,因为空,php,codeigniter,codeigniter-2,Php,Codeigniter,Codeigniter 2,制作一个表单,该表单将接受一组文本数据和图像上传 将新项添加到两个表中时,继续出现此错误: 错误号码:1048 列“id\u path”不能为空 插入缩略图id\u路径,id\u数据\u行值NULL,17 文件名:C:\wamp\www\project\system\database\DB\u driver.php 电话号码:330 我试图做的是将文本数据(如标题、文本、价格等)添加到一个tabledata中,然后上载一个图像,并将其完整上载路径作为主键添加到缩略图表中,并将插入的文本数据行的i

制作一个表单,该表单将接受一组文本数据和图像上传

将新项添加到两个表中时,继续出现此错误:

错误号码:1048

列“id\u path”不能为空

插入缩略图id\u路径,id\u数据\u行值NULL,17

文件名:C:\wamp\www\project\system\database\DB\u driver.php

电话号码:330

我试图做的是将文本数据(如标题、文本、价格等)添加到一个tabledata中,然后上载一个图像,并将其完整上载路径作为主键添加到缩略图表中,并将插入的文本数据行的id与缩略图表中的缩略图链接到缩略图表中

出于某种原因,它一直传递NULL作为缩略图表的完整上载路径

积垢。p控制器:

function add()
        {
            //Set validation properties
            $this->_set_fields();

            //Set common properties
            $data['title'] = 'Add new data row';
            $data['message'] = '';
            $data['action'] = site_url('crud/addDataRow');
            $data['link_back'] = anchor('crud/index', 'Back to list', array('class' => 'back'));

            //Load the view
            $this->load->view('templates/header', $data);
            $this->load->view('pages/crud_edit', $data);
            $this->load->view('templates/footer');
        }

        function addDataRow()
        {
            //Set common properties
            $data['title'] = 'Add new data row';
            $data['action'] = site_url('crud/addDataRow');
            $data['link_back'] = anchor('crud/index/', 'Back to list', array('class' => 'back'));

            //Set validation properties
            $this->_set_fields();
            $this->_set_rules();

            //Run validation
            if($this->form_validation->run() == FALSE)
            {
                $data['message'] = '';
            }
            else
            {
                //Save the data
                $full_file_path = null;
                $config['allowed_types'] = 'gif|jpg|png';
                $config['max_size'] = '100';
                $config['max_width']  = '1024';
                $config['max_height']  = '768';
                $path_to_uploads='./uploads';
                $config['upload_path'] = $path_to_uploads;
                $this->load->library('upload', $config);
                //add this
                $this->upload->initialize($config);
                if (!$this->upload->do_upload()){
                    $error = $this->upload->display_errors();
                    echo "<script>alert($error);</script>";
                }else{
                    $upload_data=$this->upload->data();
                    $file_name=$upload_data['file_name'];
                    $full_file_path = $path_to_uploads.'/'.$file_name;
                }


                $data_row = array(
                    'title' => $this->input->post('title'),
                    'text' => $this->input->post('text'),
                    'price' => $this->input->post('price'),
                    'status' => $this->input->post('status'),
                    'type' => $this->input->post('type')
                );

                $id = $this->crud_model->save($data_row);

                $thumbnail_row = array(
                    'id_path' => $full_file_path,
                    'id_data_row' => $id
                );

                $this->crud_model->save_thumbnail($thumbnail_row);

                //Set form input name="id"
                $this->form_validation->id = $id;

                //Set user message
                $data['message'] = '<div class="success">New data row added!</div>';
            }

            $this->load->view('templates/header', $data);
            $this->load->view('pages/crud_edit', $data);
            $this->load->view('templates/footer');
        }
编辑HTML表单代码:

用于添加新项目或更新现有项目的crud_edit.phtml表单代码:

<div id="contentColumn">
    <h1><?php echo $title; ?></h1>
    <?php echo $message; ?>
    <form method="post" action="<?php echo $action; ?>" multipart="multipart">
        <div class="data">
            <table>
                <tr>
                    <td width="30%">ID</td>
                    <td>
                        <input type="text" name="id" disabled="disabled" class="text" value="<?php echo set_value('id'); ?>"/>
                        <input type="hidden" name="id" value="<?php echo set_value('id',$this->form_data->id); ?>"/>
                    </td>
                </tr>
                <tr>
                    <td valign="top">Title<span style="color:red;">*</span></td>
                    <td>
                        <input type="text" name="title" class="text" value="<?php echo set_value('title',$this->form_data->title); ?>"/>
                        <?php echo form_error('title'); ?>
                    </td>
                </tr>
                <tr>
                    <td valign="top">Text<span style="color:red;">*</span></td>
                    <td>
                        <textarea name="text" class="text">
                            <?php echo set_value('text',$this->form_data->text); ?>
                        </textarea>
                        <?php echo form_error('text'); ?>
                    </td>
                </tr>
                <tr>
                    <td valign="top">Price<span style="color:red;">*</span></td>
                    <td>
                        <input type="text" name="price" class="text" value="<?php echo set_value('price',$this->form_data->price); ?>"/>
                        <?php echo form_error('price'); ?>
                    </td>
                </tr>
                <tr>
                    <td valign="top">Thumbnail<span style="color:red;">*</span></td>
                    <td>
                        <?php echo form_upload(array('name'=>'thumb', 'type'=>'file', 'accept'=>'image/*'))?>
                        <!--<input type="file" name="thumb" size="20" />-->
                        <?php echo form_error('thumb'); ?>
                    </td>
                </tr>
                <!--
                <tr>
                    <td valign="top">Images<span style="color:red;">*</span></td>
                    <td>
                        <input type="text" name="images" class="text" value="<?php echo set_value('images',$this->form_data->images); ?>"/>
                        <?php echo form_upload(array('name'=>'images', 'type'=>'file', 'multiple'=>'multiple', 'accept'=>'image/*'))?>
                        <?php echo form_error('images'); ?>
                    </td>
                </tr>
                -->
                <tr>
                    <td valign="top">Status</td>
                    <td>
                        <input type="text" name="status" class="text" value="<?php echo set_value('status',$this->form_data->status); ?>"/>
                        <?php echo form_error('status'); ?>
                    </td>
                </tr>
                <tr>
                    <td valign="top">Type<span style="color:red;">*</span></td>
                    <td>
                        <input type="text" name="type" class="text" value="<?php echo set_value('type',$this->form_data->type); ?>"/>
                        <?php echo form_error('type'); ?>
                    </td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td><input type="submit" value="Save" /></td>
                </tr>
            </table>
        </div>
    </form>
    <br />
    <?php echo $link_back; ?>
</div>

我的猜测是上传失败了,因为无论上传失败与否,您都在尝试进行保存。full_file_path的值将为空。顺便说一下,只保存文件名,并将路径放入显示代码中。保存路径会让将这些文件移动到另一个位置成为一件非常头疼的事情

如下更改php代码

$image1=$this->input->post('thumb');
if (!$this->upload->do_upload($image1)){

您得到的var\u dump$thumbnail\u行的id\u路径为空。id_data_行是19。在调用save_缩略图函数之前,您真的在$full_file_路径中获取了值吗?@GBD看起来不像我。我将Rick的更改应用到我的代码中,数据库错误消失了,但我仍然知道您没有选择要上载的文件!当我点击提交按钮时。已添加/插入文本数据,但缩略图表仍然为空。是否可以粘贴html表单代码??或者var_dump$\方法启动时的文件数据库错误消失,但我仍然收到echo警报$error;;单击“提交”时出错。它不会在缩略图表中插入任何新行,但不会将文本数据添加到数据表中。然后,问题在于我建议的上载。在代码的错误部分,输入print_r$error,而不是尝试回显弹出窗口;死亡这会将接收到的错误打印到屏幕上,并阻止代码继续执行,以便您有时间阅读它。它可能只是打印而不是打印,我不确定它如何返回您没有选择要上载的文件的数据。这就是当我用print_r$error替换代码的错误部分时得到的结果;死亡啊,我明白你想做什么了。。。这是一场噩梦,相信我,我经历了这一切,你必须单独做缩略图。它不会将上传作为表单的一部分提交。使用iFrame上传谷歌Ajax图像,并准备在几个小时内把你的头发拔出来。对不起,有没有办法把我的头发拔出来?我根本不需要使用代码点火器。试试这个方法$this->upload->do_upload'thumb'上传路径似乎无效。
if (!$this->upload->do_upload()){
                $error = $this->upload->display_errors();
                echo "<script>alert($error);</script>";
            }else{
                $upload_data=$this->upload->data();
                $file_name=$upload_data['file_name'];
                $full_file_path = $path_to_uploads.'/'.$file_name;
                $thumbnail_row = array(
                'id_path' => $full_file_path,
                'id_data_row' => $id
            );
                $this->crud_model->save_thumbnail($thumbnail_row);
            }
$image1=$this->input->post('thumb');
if (!$this->upload->do_upload($image1)){