【问题标题】:Is it possible to move the image by $_POST not $_FILES? [closed]是否可以通过 $_POST 而不是 $_FILES 移动图像? [关闭]
【发布时间】:2019-12-11 04:16:30
【问题描述】:

这是我的一段代码。

进程.php

$image = $_POST['image'];

index.php

<script>
function save(){
  var image = document.getElementById('image').files[0].name;

  $.ajax({
    type: "POST",
    url: 'process.php',
    data: {
      image: image
    },
  });
}
</script>

<input type="file" class="custom-file-input" id="image" name="image">

这基本上只将文件名返回到数据库mysql,但我不知道如何将文件从文件夹A移动到文件夹B。文件夹A是图像的来源,文件夹B是当我想调用图像时,我会使用文件夹 B 的路径。

是否可以通过 $_POST 而不是 $_FILES 移动图像?因为到目前为止 我只找到 $_FILES。

【问题讨论】:

  • .. ((忘记添加
    ))
  • 据我所知这是不可能的,您只能通过 $_FILES 获取文件信息
  • 你不能发帖,你需要$_FILES
  • 为什么要使用$_POST
  • 您想通过使用 $_POST 而不是 $_FILES 来解决什么问题?

标签: javascript php jquery mysql ajax


【解决方案1】:

您需要将图片作为数据 url 发送:

<input type="file" accept="image/*" onchange="loadFile(event)">
<script>
var img = "";
  var loadFile = function(event) {
    var output = document.getElementById('output');
    img = URL.createObjectURL(event.target.files[0]);
  };
function save(){
  var image = img;
  $.ajax({
    type: "POST",
    url: 'process.php',
    data: {
      image: image
    },
  });
}
</script>

PHP:

$image = $_POST['image'];//now you can save the data url in database also

【讨论】:

  • 请注意,图片大小必须小于 1 mb,否则某些浏览器会崩溃!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-11
  • 2011-01-04
相关资源
最近更新 更多