Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.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 OpenCart多重上传_Php - Fatal编程技术网

Php OpenCart多重上传

Php OpenCart多重上传,php,Php,我这里有个问题,我在opencart上建立了一个简单的多重上传功能,文件保存在文件夹上,但不保存路径n mysql,有人能帮我吗 视图: <input type="file" name="picture[]" accept="img/*" /> <input type="file" name="picture[]" accept="img/*" /> 型号: $this->db->query("INSERT INTO " . DB

我这里有个问题,我在opencart上建立了一个简单的多重上传功能,文件保存在文件夹上,但不保存路径n mysql,有人能帮我吗

视图:

       <input type="file" name="picture[]" accept="img/*" />
       <input type="file" name="picture[]" accept="img/*" />
型号:

$this->db->query("INSERT INTO " . DB_PREFIX . "product_image SET image = '" . $this->db->escape($data['img']) . "',product_id = '" . (int)$product_id . "'");

您可以查看我使用imageresize调整上传图像大小并覆盖的代码。您可以跳过该部分,只需遵循上传图像的循环即可。几周前,我修改了当前的OpenCart最新版本(2.0.1.1),以支持使用DropZone.js上传多个图像。我正在公开此项目,因此您可以从此处下载文件:

MySQL查询会出现什么错误?这可能有助于显示更多上下文。强制转换为int,然后另存为字符串。。。(int)$product_idMike Brant:mysql没有错误,但它只保存了1个图像,我上传了2个图像,它只在mysql中保存了第2个图像,我认为我的控制器有问题;它显示a.jpg2.jpg,在mysql中只保存2.jpg。在文件夹中它保存了2个图像。这看起来不错,我可以把代码放在哪里测试?在敞篷车1.5.5.1中
$this->db->query("INSERT INTO " . DB_PREFIX . "product_image SET image = '" . $this->db->escape($data['img']) . "',product_id = '" . (int)$product_id . "'");
public function create(){
        global $database;
        if(isset($_FILES['fupload'])){
            $data = $_FILES["fupload"]["error"];
            // loops through shops that has been selected and store category associated with store
            foreach ($_FILES["fupload"]["error"] as $key => $error) {
                //checks if there is no error
              if ($error == UPLOAD_ERR_OK) {
                move_uploaded_file($_FILES['fupload']['tmp_name'][$key],"../public/gallery/".basename($_FILES['fupload']['name'][$key]));
                $image = new Imageresize(); // an instance of image resize object
                $image->load("../public/gallery/".basename($_FILES['fupload']['name'][$key]));
                //$image->image =;
                $image->resize(400,400);
                $image->save("../public/gallery/".basename($_FILES['fupload']['name'][$key]));

                //this section is needed to get the extension for image type in renaming the image
                if ($_FILES['fupload']['type'][$key]=="image/gif"){
                    $ext = ".gif";
                }
                if ($_FILES['fupload']['type'][$key]=="image/png"){
                    $ext = ".png";
                }
                if ($_FILES['fupload']['type'][$key]=="image/jpeg"){
                    $ext = ".jpeg";
                }
                if ($_FILES['fupload']['type'][$key]=="image/pjpeg"){
                    $ext = ".jpeg";
                }
                if ($_FILES['fupload']['type'][$key]=="image/gif"){
                    $ext = ".gif";
                }
                if ($_FILES['fupload']['type'][$key]=="image/jpg"){
                    $ext = ".jpg";
                }
                $new_name = uniqid()."_".time().$ext; //new name for the image
                rename("../public/gallery/".basename($_FILES['fupload']['name'][$key]),"../public/gallery/".$new_name);
                $photo = $new_name;
                $sqlImg = "INSERT INTO gallery (img_url) VALUES ('$photo') ";

                        $Result = $database->db_query($sqlImg);

              }
            }
        }
    }