HTML5 drag and drop and multiple file upload

前端 未结 4 691
轮回少年
轮回少年 2021-02-06 14:53

I have an HTML form that contains a file input field with multiple file selection and I also have a drag and drop feature that I am working on as well. My question is how to int

4条回答
  •  南方客
    南方客 (楼主)
    2021-02-06 15:28

    I wrote some jQuery code that does just that, tell me if it works for you.

    
    
      
        Multiple DnD Uploader
        
        
        
      
      
        

    Drop files here

    To add them as attachments

    And the PHP file looks like this:

     $v){   
        if(substr($k, 0, 5) == "HTTP_"){
          $k = str_replace('_', ' ', substr($k, 5));
          $k = str_replace(' ', '-', ucwords(strtolower($k)));
          $headers[$k] = $v;
        }
      } 
      $file = new stdClass;
      $file->name = basename($headers['X-File-Name']);
      $file->size = $headers['X-File-Size'];
      $file->content = file_get_contents("php://input");
      if(file_put_contents('files/'.$file->name, $file->content))
        echo $_GET['id'];
    ?>
    

提交回复
热议问题