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 に答える