首頁 > 後端開發 > php教程 > php 使用dropzonejs拖曳檔案上傳,如何將處理結果回顯到目前頁面的textarea中?

php 使用dropzonejs拖曳檔案上傳,如何將處理結果回顯到目前頁面的textarea中?

WBOY
發布: 2023-03-01 22:40:01
原創
1542 人瀏覽過

修改了下dropzonejs的demo上傳頁面:(原位址:http://www.dropzonejs.com/exa...)加了個textarea,想實作檔案上傳處理完成後將處理結果回顯到textarea內,請問該如何處理?


以下是index.php檔案內容:

<code><!DOCTYPE html>
<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><!DOCTYPE html>
<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
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板