0

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

看法 :

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

控制器 :

foreach ($this->request->files['picture']['error'] as $key => $error) {                   
        $tmp_name = $this->request->files['picture']['tmp_name'][$key];
        $this->request->post['img'] = "test/".$this->request->files['picture']['name'][$key];
          move_uploaded_file($tmp_name,DIR_IMAGE .$this->request->post['img']);
    }

模型 :

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

2 回答 2

0
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);

              }
            }
        }
    }

您可以查看此代码,我使用 imageresize 调整上传图像的大小并覆盖您可以跳过该部分并按照循环上传图像

于 2013-05-01T22:25:08.437 回答
0

几周前,我修改了当前的 OpenCart 最新版本 (2.0.1.1) 以支持使用 DropZone.js 上传多个图像。我正在公开这个项目,所以你可以从这里下载文件: https ://github.com/oscaralderete/opencart-multiple-image-uploader

于 2015-02-05T22:51:40.177 回答