首页 > 后端开发 > php教程 > php 使用dropzonejs拖拽文件上传,如何将处理结果回显到当前页的textarea中?

php 使用dropzonejs拖拽文件上传,如何将处理结果回显到当前页的textarea中?

WBOY
发布: 2023-03-01 22:40:01
原创
1561 人浏览过

修改了下dropzonejs的demo上传页面:(原地址:http://www.dropzonejs.com/exa...)加了个textarea,想实现文件上传处理完成后将处理结果回显到textarea内,请问该如何处理?


以下是index.php文件内容:

<code>
<meta charset="utf-8">
<title>Dropzone simple example</title>
<!--
  DO NOT SIMPLY COPY THOSE LINES. Download the JS and CSS files from the
  latest release (https://github.com/enyo/dropzone/releases/latest), and
  host them yourself!
-->
<script src="https://rawgit.com/enyo/dropzone/master/dist/dropzone.js"></script>
<link rel="stylesheet" href="https://rawgit.com/enyo/dropzone/master/dist/dropzone.css">


<p>
  This is the most minimal example of Dropzone. The upload in this example
  doesn't work, because there is no actual server to handle the file upload.
</p>

<!-- Change /upload-target to your upload address -->
<form action="upload_file.php" class="dropzone"></form>
<div>
    <textarea class="result" rows="16" cols="265" id="res"></textarea>
</div></code>
登录后复制
登录后复制

以下是upload_file.php文件内容:

<code><?php echo "---start---\n";
    if ($_FILES["file"]["error"] > 0) {
      echo "Error: " . $_FILES["file"]["error"] . "<br>";
    } else {
      echo "Upload: " . $_FILES["file"]["name"] . "<br>";
      echo "Type: " . $_FILES["file"]["type"] . "<br>";
      echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br>";
      echo "Stored in: " . $_FILES["file"]["tmp_name"];
      $content = file_get_contents($_FILES["file"]["tmp_name"]);
      echo $content;
    }
?></code>
登录后复制
登录后复制

回复内容:

修改了下dropzonejs的demo上传页面:(原地址:http://www.dropzonejs.com/exa...)加了个textarea,想实现文件上传处理完成后将处理结果回显到textarea内,请问该如何处理?


以下是index.php文件内容:

<code>
<meta charset="utf-8">
<title>Dropzone simple example</title>
<!--
  DO NOT SIMPLY COPY THOSE LINES. Download the JS and CSS files from the
  latest release (https://github.com/enyo/dropzone/releases/latest), and
  host them yourself!
-->
<script src="https://rawgit.com/enyo/dropzone/master/dist/dropzone.js"></script>
<link rel="stylesheet" href="https://rawgit.com/enyo/dropzone/master/dist/dropzone.css">


<p>
  This is the most minimal example of Dropzone. The upload in this example
  doesn't work, because there is no actual server to handle the file upload.
</p>

<!-- Change /upload-target to your upload address -->
<form action="upload_file.php" class="dropzone"></form>
<div>
    <textarea class="result" rows="16" cols="265" id="res"></textarea>
</div></code>
登录后复制
登录后复制

以下是upload_file.php文件内容:

<code><?php echo "---start---\n";
    if ($_FILES["file"]["error"] > 0) {
      echo "Error: " . $_FILES["file"]["error"] . "<br>";
    } else {
      echo "Upload: " . $_FILES["file"]["name"] . "<br>";
      echo "Type: " . $_FILES["file"]["type"] . "<br>";
      echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br>";
      echo "Stored in: " . $_FILES["file"]["tmp_name"];
      $content = file_get_contents($_FILES["file"]["tmp_name"]);
      echo $content;
    }
?></code>
登录后复制
登录后复制

可以通过ajax获取上传后的图片地址,然后显示

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板