Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.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 arrray中的变量值作为整数返回,但codeigniter中需要字符串_Php_Arrays_Codeigniter_Variables - Fatal编程技术网

Php arrray中的变量值作为整数返回,但codeigniter中需要字符串

Php arrray中的变量值作为整数返回,但codeigniter中需要字符串,php,arrays,codeigniter,variables,Php,Arrays,Codeigniter,Variables,大家好,我完全被这个问题困住了 我想将我使用codeigniter中的字符串“rename”函数更改的文件名添加到一个数组中,然后将该数组发送到一个模型,在那里我可以提取该数组并将其添加到我的数据库中 但是,当我执行此操作时,在数据库中为文件名添加的值始终为“1” 这是我的代码,在里面我上传并存档 这是控制器类的一部分,文件名已更改并添加到数组中 $data = array('upload_data' => $this->upload->data()); //

大家好,我完全被这个问题困住了

我想将我使用codeigniter中的字符串“rename”函数更改的文件名添加到一个数组中,然后将该数组发送到一个模型,在那里我可以提取该数组并将其添加到我的数据库中

但是,当我执行此操作时,在数据库中为文件名添加的值始终为“1”

这是我的代码,在里面我上传并存档

这是控制器类的一部分,文件名已更改并添加到数组中

        $data = array('upload_data' => $this->upload->data()); // Get the file from the form userfile information
        $file = $data['upload_data']['file_name'];

        //hacky name generator
        $randomstring = random_string('alnum', 4);
        $filenew = rename($dir . $file, $dir . $id . '_' . $randomstring . '.jpg'); //basic php rename call, rename my upload now that upload finished

        // this array is all the other values from my form fields
        $data = array($this->input->post('comment'), $filenew);

        $configB['image_library'] = 'gd2'; // this code begins the thumbnail making process, from user guide
        $configB['source_image'] = $filenew;//$dir . $id.'.jpg'; // I am using $id for image name, which is my users id, comes from the session
        $configB['create_thumb'] = FALSE;
        $configB['maintain_ratio'] = TRUE;
        $configB['width'] = 300;
        $configB['height'] = 300;
        $this->image_lib->initialize($configB); 
        $this->image_lib->resize();

        $this->load->model('membership_model'); 
        // run my model which saves all this to the database, image name also ($filenew)   
        if($query = $this->membership_model->create_post($id,$data)) 
        {
            $data = array('upload_data' => $this->upload->data());
            $data['filename'] = $filenew; 
            $this->load->view('post_success_view', $data);

        }
这是模型

function create_post($id, $data) 
{
    //get data from array
            $content = $data[0];
    $filename = $data[1]; 

    // update database to track a new post.
    $new_post_insert_data = array(
        'content' => $content,
        'beer_down' => 0,
        'beer_up' => 0,
        'user_name' => $this->session->userdata('username'),
        'account_id' => $this->session->userdata('userid'),
        'file_name' => $filename
        );

    $insert_post = $this->db->insert('post', $new_post_insert_data);
    return $insert_post;    
}
如果您能帮助我解决在这里被困数小时的问题,请提前向您表示感谢。

rename()更改系统资源的名称,并返回Bool表示成功。当您将该布尔值转换为真字符串时,将得到“1”。如果要在数据库中存储名称,应设置一个变量,即:

$new_name = $dir . $id . '_' . $randomstring . '.jpg';
然后调用重命名:

rename($dir . $file, $new_name);

并使用$new\u名称插入数据库。

数据库中文件名的字段类型是什么?该代码与。。。目录中有什么?尝试执行
重命名($data['full_path']等)不是
文件名
!Khez它实际上是相同的代码,只是稍微修改了一些位和片段:p@matthew当前位置不要忘记标记已接受的答案,如果我知道问题已解决,我本可以跳过此帖子。养成这样做的习惯当有人为你解决问题时,他们应该得到表扬。甚至没有意识到这个功能的存在,仍然在使用它。