pdf文件上传并存储在javascript文件夹中

时间:2017-04-29 02:49:06

标签: javascript jquery jquery-file-upload

我是java脚本的初学者。我想在java脚本中上传文件(pdf)并存储在特定文件夹中。我不能这样做。请帮助..我在php中做。但我也是用java脚本做的。

这是我的php代码......

<form action="<?php print $PHP_SELF?>" enctype="multipart/form-data" method="post">
   Last Name:<br /> <input type="text" name="name" value="" /><br />
   Homework:<br /> <input type="file" name="homework" value="" /><br />
   <p><input type="submit" name="submit" value="Submit Notes" /></p>
</form>

<?php
   define ("FILEREPOSITORY","./");

   if (isset($_FILES['homework'])) {

      if (is_uploaded_file($_FILES['homework']['tmp_name'])) {

         if ($_FILES['homework']['type'] != "application/pdf") {
            echo "<p>Homework must be uploaded in PDF format.</p>";
         } else {
            $today = date("m-d-Y");
            if (! is_dir(FILEREPOSITORY.$today)) {
               mkdir(FILEREPOSITORY.$today);
            }
            $name = $_POST['name'];
            $result = move_uploaded_file($_FILES['homework']['tmp_name'], FILEREPOSITORY.$today."/"."$name.pdf");

            if ($result == 1) 
               echo "<p>File successfully uploaded.</p>";
            else 
               echo "<p>There was a problem uploading the homework.</p>";
         }
      }
   }
?>

我也想在php api中上传pdf文件。

1 个答案:

答案 0 :(得分:1)

您可以使用Jquery文件上传功能。这是一个链接,研究代码和实现。 https://blueimp.github.io/jQuery-File-Upload/