Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

Variáveis ​​$_POST não funcionam com $_FILES e multipart/form-data


Você só precisa mover seu arquivo para dentro de sua instrução if e alterar $_POST['filebutton'] para $_FILES['filebutton']

Sempre que você faz um upload de arquivo, os arquivos são preenchidos no $_FILES variável global e os outros campos são preenchidos no $_POST variável global.
<?php
$uploaddir = "/var/www/img/pictures/";
if (isset($_FILES['filebutton'])) {  
    $uploadfile = $uploaddir . basename($_FILES['filebutton']['name']);
    move_uploaded_file($_FILES['filebutton']['tmp_name'], $uploadfile);
    $pictureUpdate = ", PICTURE_FILEPATH = '" . $_FILES['filebutton'] . "'";
} else {
    $pictureUpdate = "";
}
$connection = mysqli_connect("1.2.3.4","xxxx","xxxx","xxxx") or die("Caonnot connect to database.");
$update = "UPDATE table SET COLUMN1='" . $_POST['text1'] . "', COLUMN2='" . $_POST['text2'] . "' . $pictureUpdate . " where COLUMN3 = " . $_POST['text1'] . " ";
$update_sql = mysqli_query($connection, $update) or die("Cannot connect to mysql table. ". $update);
header("Location: " . $_SERVER['REQUEST_URL'] . "?success=1");
exit();

tente este código e veja o que ele faz por você, se isso funcionar e o outro não, isso significa que há mais no seu código que precisamos para resolver o problema.
<form name="myForm" METHOD="POST" ACTION="" enctype="multipart/form-data">
  <input type="text" name="text1" id="text1">
  <input type="text" name="text2" id="text2">
  <input type="file" name="filebutton" id="filebutton">
  <input type="submit" name="submit" id="submit">
</form>
<xmp><?php if ($_SERVER['REQUEST_METHOD'] === 'POST') { var_dump($_FILES, $_POST); } ?></xmp>
array(1) {
  ["filebutton"]=>
  array(5) {
    ["name"]=>
    string(21) "scanParser.properties"
    ["type"]=>
    string(24) "application/octet-stream"
    ["tmp_name"]=>
    string(14) "/tmp/phpRm1Ytp"
    ["error"]=>
    int(0)
    ["size"]=>
    int(264)
  }
}
array(3) {
  ["text1"]=>
  string(1) "1"
  ["text2"]=>
  string(1) "2"
  ["submit"]=>
  string(6) "Submit"
}