Custom page form action wordpress admin

I added a custom page in wordpress admin from from functions.php. And add a form on and trying to perform action on same page.

Here you can see actually what happenes, here is the url of backend my site goo.gl/jLfsDo . Username is admin and password is testwooc++ . On the left menu bar A admin menu bar with title “Upload COD File”. I added it on functions.php of current theme and need to add action result at the same page. But its not working.

/*******************/
/*Form starts here*/
/*****************/
<div style="width:750px;">
<h1><span style="position:relative;top:-7px">Upload COD file</span></h1>
<form action="<?php the_permalink(); ?>" method="post" enctype="multipart/form-data">
  Please choose a file: <input type="file" name="uploadFile"><br>
  <input type="submit" value="Upload File">
</form> 




/*Form action starts here */
<?php 
  if(isset($_POST['submit'])) {
    $target_dir =  basename( $_FILES["uploadFile"]["name"]);
    $uploadOk=1;
    $contents2 = "";
    if (move_uploaded_file($_FILES["uploadFile"]["tmp_name"], $target_dir)) {
        echo "The file ". basename( $_FILES["uploadFile"]["name"]). " has been uploaded.";

      $CSVfp = fopen($target_dir, "r");
      if($CSVfp !== FALSE) 
       while(!feof($CSVfp)) {
       $data = fgetcsv($CSVfp, 3000, ",");
       $contents2 .=  $data[3]; 
       $var_str = var_export($contents2, true);
       $file = 'new_file.txt';
       $var_str = str_replace("'",",",$var_str);
       // $var_str2 = str_replace(" ",",",$var_str);
       // $var_str3 = str_replace(",,",",",$var_str2);
       $var_str3 = ltrim($var_str,"Pin,");
       $var_str3 = implode(",", str_split($var_str3, 6))." ";
       $var_str4 = str_replace(",,","",$var_str3);
       file_put_contents($file, $var_str4);
    } 

    }
    else {
        echo "Sorry, there was an error uploading your file.";
    }

?> 
<form method="get" action="new_file.txt">
<button type="submit">Download!</button>
</form>
<?php
   }

?>

Related posts

Leave a Reply