Home > Backend Development > PHP Tutorial > PHP uses dropzonejs to drag and drop files to upload. How to echo the processing results to the textarea of ​​the current page?

PHP uses dropzonejs to drag and drop files to upload. How to echo the processing results to the textarea of ​​the current page?

WBOY
Release: 2023-03-01 22:40:01
Original
1542 people have browsed it

Modified the demo upload page of dropzonejs: (Original address: http://www.dropzonejs.com/exa...) Added a textarea. I want to realize that after the file upload processing is completed, the processing results will be echoed to the textarea. What should I do?


The following is the content of the index.php file:

<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>
Copy after login
Copy after login

The following is the content of the upload_file.php file:

<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>
Copy after login
Copy after login

Reply content:

Modified the demo upload page of dropzonejs: (Original address: http://www.dropzonejs.com/exa...) Added a textarea. I want to realize that after the file upload processing is completed, the processing results will be echoed to the textarea. What should I do?


The following is the content of the index.php file:

<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>
Copy after login
Copy after login

The following is the content of the upload_file.php file:

<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>
Copy after login
Copy after login

You can get the uploaded image address through ajax and then display it

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template