Upload a json file in php [closed]

I’m trying to upload a json file through PHP. This is the code that i have yet.

if( isset( $_POST['upload'] )) {
    $target = "https://wordpress.stackexchange.com/";
    $target = $target . basename( $_FILES['upload']['name']) ;
    if(move_uploaded_file($_FILES['upload']['tmp_name'], $target))
    {
        echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
    }
    else {
        echo "Sorry, there was a problem uploading your file.";
    }
}

I have Browse button and an Import button, and when i press Import, it doesn’t say anything.

 echo '<div class="wrap">';
echo "<form action='' method='post' enctype="multipart/form-data"><input type="file" name="upload" value="Upload" id='upload' /></form>";
echo '</div>';
echo '<div class="wrap">';
echo "<form action='' method='post'><input class="button-secondary" type="submit" name="import" value="Import" id='import' /></form>";
echo '</div>';

This is the code for the buttons.

Any idea how could I solve this issue?

1 Answer
1

You have the browse button and the import button in two different HTML form elements. Don’t do that, put them in the same <form>.

Leave a Comment