首页 > 解决方案 > 如何在 smarty 框架 (*.tpl) 中将图像发送到服务器?我已经写好了预览图片代码,但是我不知道怎么发送

问题描述

如何在 smarty 框架 (*.tpl) 中将图像发送到服务器?我已经编写了预览图像代码,但我不知道如何发送它。

这是 *.tpl 代码

function image_show(){
  var image = "";
  //images.forEach((i) => {
    //console.log(i);
  //})
  images.forEach((i) =>{
    image += `<div><img src="`+i.url+`"><span onclick="delete_image(`+images.indexOf(i)+`)">&times;</span></div>`;
  })
  return image;
}

function delete_image(e){
  images.splice(e,1);
  document.getElementById('container').innerHTML = image_show();
}

function check_duplicate(name){
    var image = true;
    if(images.length >0){
      for(e=0; e<images.length; e++){
        if(images[e].name == name){
          image = false;
          break;
        }
      }
    }
    return image;
}

<form action="#" method="post" id="form">
<div>
                <input type="file" id="image" name="Image" multiple="" onchange="image_select()">
                <button type="button" onclick="document.getElementById('image').click()">Choose Images</button>
              </div>
              <div id="container"></div>
</form>

当用户选择图像时,它可以预览图像,但如何上传到服务器?

在php中,我可以使用这种方法

<form action="upload.php" method="post" enctype="multipart/form-data">

但是,在 smarty framewodk 中我可以使用哪种方法呢?

这是聪明的代码

$this->context->smarty->assign([
          'PGWD'   => $_SERVER['QUERY_STRING'],
          'application_page' => $application_page,
          'application_process' => $application_process,
          'js' =>$js,
        ]);

那么,我是使用 ajax 方法还是其他类似的功能?

标签: phphtmlajaxsmarty

解决方案


推荐阅读