Php Codeigniter:在for循环中设置上载文件名

Php Codeigniter:在for循环中设置上载文件名,php,mysql,codeigniter,wamp,Php,Mysql,Codeigniter,Wamp,我在Codeigniter的for循环中设置上传文件名时遇到问题,我想将上传的文件(歌曲)添加到数据库和某个文件夹中。我想把它们命名为歌曲1,歌曲2,歌曲3。。。其中number是数据库中歌曲的ID。这是我的密码: for ($i = 1; $i < 201; $i++) { if (isset($_POST['name'.$i])) { $maxID = $this->Song_model->maxID();

我在Codeigniter的for循环中设置上传文件名时遇到问题,我想将上传的文件(歌曲)添加到数据库和某个文件夹中。我想把它们命名为歌曲1,歌曲2,歌曲3。。。其中number是数据库中歌曲的ID。这是我的密码:

   for ($i = 1; $i < 201; $i++) {

        if (isset($_POST['name'.$i])) {

            $maxID = $this->Song_model->maxID();
            $maxID++;
            $config['file_name'] = "song".$maxID;
            $config['upload_path'] = "./assets/uploads/";
            $config['allowed_types'] = '*';
            $config['max_size'] = 0;
            $this->load->library('upload', $config);

            if ($this->upload->do_upload('file'.$i) == true) {
                $data = array(
                    'IDArt' => $artistID,
                    'IDAlb' => $newAlbumId,
                    'songname' => $this->input->post('name'.$i),
                    'author' => $artistName,
                    'length' => $this->input->post('length'.$i),
                    'price' => $this->input->post('price'.$i)
                );
                $this->Song_model->persist($data);
            }


        }

    }
($i=1;$i<201;$i++)的
{
如果(isset($_POST['name'.$i])){
$maxID=$this->Song_model->maxID();
$maxID++;
$config['file_name']=“song”。$maxID;
$config['upload_path']=”/assets/uploads/”;
$config['allowed_types']='*';
$config['max_size']=0;
$this->load->library('upload',$config);
如果($this->upload->do_upload('file'.$i)==true){
$data=数组(
“IDArt”=>$artistID,
'IDAlb'=>$newAlbumId,
“songname”=>$this->input->post('name'.$i),
“作者”=>$artistName,
'length'=>this->input->post('length'.$i),
“价格”=>$this->input->post('price'.$i)
);
$this->Song_model->persist($data);
}
}
}
我上传的很多歌曲中的第一首歌都有好名字示例:song11(以前数据库中有10首歌),但在这首歌之后的歌曲,名字分别是song111和Song112

代码段:
$maxID=$this->Song_model->maxID()
$maxID++

获取我需要与“歌曲”连接的确切ID,但是,$config['file\u name']=“歌曲”。$maxID这条线


顺便说一句,song11、song111、song112当文件上传名设置为相同的值时会发生这种情况,在本例中为“song11”

我终于找到了解决方案,我用bool move_uploaded_file函数修复了它,该函数可以在上传后动态更改文件名。

为什么要使用“file”。$I当你想要的时候,我想你想要的是$config['file_name']?@thomasw_lrd'file'.$i是客户端输入type=“file”的位置,我有多个文件字段,所以我将'file'+整数放在精确字段中?