I need to insert into the MySQL Database (table fotos
) the path that is set to $target_file_name
. I believe that the error is probably at the time of INSERT
.
File conexao.php
:
try {
$PDO = new PDO($dsn, $usuario, $senha);
// echo "SUCESSO";
} catch (PDOException $erro) {
//echo "ERRO: " .$erro.getMessage();
// echo "conexao_erro";
exit;
}
?>
File upload_image.php
:
<?php
include "conexao.php";
$target_dir = "upload/";
$target_file_name = $target_dir .basename($_FILES["file"]["name"]);
$response = array();
if (isset($_FILES["file"]))
{
if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file_name))
{
$success = true;
$message = "Sucesso !";
$sql_insert = "INSERT FROM fotos (foto_url) VALUES (:TARGET_FILE_NAME)";
$stmt = $PDO ->prepare($sql_insert);
$stmt -> bindParam(':TARGET_FILE_NAME', $target_file_name);
$stmt -> execute();
}
else
{
$success = false;
$message = "Erro no upload !";
}
}
else
{
$success = false;
$message = "Favor inserir arquivo !";
}
$response["success"] = $success;
$response["message"] = $message;
echo json_encode($response);
?>