0

I'm trying to create a simple fileupload form in my custom Wordpress template:

<form action="<?php echo $current_url = home_url(add_query_arg(array(),$wp->request)); ?>" method="post" enctype="multipart/form-data">
                <label for="file">Filename:</label>
                <input type="file" name="file" id="file"><br>
                <input type="submit" name="submit" value="Submit">
</form>

On submit, the $_FILES array is empty.

I think the problem is in the action, as the url that is generated is the nice URL, instead of http://domain.com/somepost.php

What should I put into the action, so I get the $_FILES?

2
  • Just blank your action and you get $_FILES ARRAY your same page if you form is submitted.. Commented Mar 26, 2014 at 11:21
  • When I leave the action blank, for some reason I get empty $_FILES array... Commented Mar 26, 2014 at 14:13

1 Answer 1

1

Try this

 <?php
      if(isset($_POST['submit'])){
            if($_FILES["file"]["error"] > 0){
        echo $_FILES["file"]["error"];
    }
            else{
                    echo $_FILES['file']["name"]; //  your file name
            }
       }
 ?>
 <form method="post" action="#" enctype="multipart/form-data">
 <input type="file" name="file" />
 <input type="submit" name="submit"/>
 </form>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.