how to Create Front-end Multiple File Upload – WordPress - Welcome To PgeJoint

Welcome To PgeJoint

Get Everything Here

Monday 31 July 2017

how to Create Front-end Multiple File Upload – WordPress

create-front-end-multiple-file-upload-wordpress
WordPress  can provide you multiple file upload support and drag and drop support on admin section. If  you wish to bring the same service on your WordPress front end is easy and the following code help you to create multiple file upload with the help of HTML5 Forms and simple WP function.

<form action="pge-upload.php" method="post" enctype="multipart/form-data" name="front_end_upload" >

 <label> Attach all your files here :<input type="file" name="pge_multiple_attachments[]"  multiple="multiple" > </label>

<input type="submit" name="Upload" >

</form>
 
 
\The above form sent the form data to the HTML file pge-upload.php  . Here is the simple upload php function to handle multiple files simultaneously.
 
//pge-upload.php 
if( 'POST' == $_SERVER['REQUEST_METHOD']  ) {
if ( $_FILES ) { 
  $files = $_FILES["pge_multiple_attachments"];  
  foreach ($files['name'] as $key => $value) {    
    if ($files['name'][$key]) { 
     $file = array( 
      'name' => $files['name'][$key],
       'type' => $files['type'][$key], 
      'tmp_name' => $files['tmp_name'][$key], 
      'error' => $files['error'][$key],
       'size' => $files['size'][$key]
     ); 
     $_FILES = array ("pge_multiple_attachments" => $file); 
     foreach ($_FILES as $file => $array) {    
      $newupload = pge_handle_attachment($file,$pid); 
     }
    } 
   } 
  }

} 

No comments:

Post a Comment