move_uploaded_file两个或多个不同的图片名称只移动一个

move_uploaded_file two or more different image names moves only one

我试图同时以一种形式移动五个不同的文件,但只有一个图像移动。我的数据库 table 中的每个文件名都有五列。上传的图片名称保存在数据库列中,但唯一的问题是只移动了一个文件,而不是所有上传的文件。下面是代码:

 //form isValid...
 $post = $form2->getData();

            $imageonetmp = $post["imageone"]["tmp_name"];
            $imageonename = $post["imageone"]["name"];

            $imagetwotmp = $post["imagetwo"]["tmp_name"];
            $imagetwoname = $post["imagetwo"]["name"];

            $imagethreetmp = $post["imagethree"]["tmp_name"];
            $imagethreename = $post["imagethree"]["name"];

            $imagefourtmp = $post["imagefour"]["tmp_name"];
            $imagefourname = $post["imagefour"]["name"];

            $imagefivetmp = $post["imagefive"]["tmp_name"];
            $imagefivename = $post["imagefive"]["name"];

            $filepath = $this->_dir.$imageonename;
            $filepath = $this->_dir.$imagetwoname;
            $filepath = $this->_dir.$imagethreename;
            $filepath = $this->_dir.$imagefourname;
            $filepath = $this->_dir.$imagefivename;


            move_uploaded_file($imageonetmp, $filepath);
            move_uploaded_file($imagetwotmp, $filepath);
            move_uploaded_file($imagethreetmp, $filepath);
            move_uploaded_file($imagefourtmp, $filepath);
            move_uploaded_file ($imagefivetmp, $filepath);

 /*set image names to db here*/
 $entityManager->persist($autos);
            $entityManager->flush();

希望有人能提供帮助。

您正在使用相同的变量名 $filepath 来写入文件。这意味着您正在移动每个文件但会覆盖之前的移动。

您应该使用不同的变量名称,例如$filepath1、$filepath2 等...

$filepath = 文件位置... 移动文件...

并重复。