简体   繁体   English

PHP 使用 Post 方法上传

[英]PHP Upload using Post method

I was wondering if anyone could help me figure out how to add the following我想知道是否有人可以帮助我弄清楚如何添加以下内容

  • multi-file drag and drop feature and to log the location of each file after upload using the below多文件拖放功能,并在上传后使用以下记录每个文件的位置
  • "echo "Uploaded to: ". "localhost/site/uploads/". $_FILES['uploaded_file']["name"];" "echo "上传到:"。"localhost/site/uploads/"。$_FILES['uploaded_file']["name"];"
  • file size limitation to 100MB文件大小限制为 100MB
  • The bonus feature is to have an HTML select multiple Attribute to choose other folders to upload in for example, the current folder is "upload" but I'd like to have another 3 as options to upload into it奖励功能是有一个 HTML select 多个属性来选择要上传的其他文件夹,例如,当前文件夹是“上传”,但我想再有 3 个作为上传到它的选项
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Manual file upload</title>
  <link rel="stylesheet" href="style.css">
</head>


<body>

<div class="area">
  <form enctype="multipart/form-data" action="index.php" method="POST">
    <p>Upload your file</p>
    <input class="button1" type="file" multiple="multiple" name="uploaded_file"></input><br/>
    <input class="button2" type="submit" value="Upload"></input>
  </form>
</div>

<?PHP
   if(!empty($_FILES['uploaded_file']))
   {
     $path = "uploads/";
     $path = $path . basename( $_FILES['uploaded_file']['name']);

     if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $path)) {
       echo "Uploaded to: " . "loclahost/site/uploads/" . $_FILES['uploaded_file']["name"];
     } else{
         echo "There was an error uploading the file, please try again!";
     }
   }

?> 

</body>
</html>

you just need to add select box in it.您只需要在其中添加 select 框。 for ex.例如。

<select name="folder_name">
      <option value="upload">Uploads</option>
      <option value="upload1">Uploads 1</option>
      <option value="upload2">Uploads 2</option>
</select>

in php:在 php 中:

  $path = $_POST['folder_name'];     // instead of static - $path = "uploads/";

on every file uploading you can change the path if not it will select the default value of select box.在每个文件上传时,您可以更改路径,如果不是,它将 select select 框的默认值。 you can change the name of the folder as your need.您可以根据需要更改文件夹的名称。 I think this will solve your problem.我认为这将解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM