class TableDirectoryCleaner
{
private array $ids = [];
private array $filenames = [];
public function doTheBeauty()
{
$this->init();
$this->checkTableAndDeleteRowsWithoutFiles();
$this->checkFolderAndDeleteFilesWithousRow();
}
private function init()
{
$this->fillIds();
$this->fillFilenames();
}
private function fillIds()
{
$this->ids = $this->getRepository(Save::class)->findAllIdsAsArray();
}
private function fillFilenames()
{
$this->filenames = $this->someMethodThatGetsFilenamesAsArray();
}
private function checkTableAndDeleteRowsWithoutFiles()
{
foreach ($this->ids as $id) {
if (!array_search($id, $this->filenames)) {
$this->getRepository(Save::class)->deleteRowWithId($id);
}
}
}
private function checkFolderAndDeleteFilesWithousRow()
{
foreach ($this->filenames as $filename) {
if (!array_search($filename, $this->ids)) {
unlink($filename);
}
}
}
}
//я бы на вашем месте попробовал вот так для начала
require('connect.php');
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if (isset($_POST['username']) && isset($_POST['password'])) {
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
$countUsersQuery = 'SELECT count(id) as count_users FROM users WHERE username=?';
$query = $conn->prepare($countUsersQuery);
$query->execute([$username]);
$countUsersResult = $query->fetch();
if ((int)$countUsersResult['count_users'] === 0) {
$insertUserQuery = "
INSERT INTO users (`username`, `password`, `email`)
VALUES ('$username', '$password', '$email')";
} else {
echo "<script>alert('Логин уже занят')</script>";
}
if ($conn->query($insertUserQuery) === true) {
header("Location: /");
} else {
echo "Error: " . $insertUserQuery . "<br>" . $conn->error;
}
$conn->close();
}
$response = curl_exec($ch);
if ($errno = curl_errno($ch)) {
$message = curl_strerror($errno);
echo "cURL error ({$errno}):\n {$message}";
}
curl_close($ch);
var freeDelivery = {
enabled: true,
summa: freed()
};
function freed() {
var getfree;
$.ajax({
method: "GET",
url: "getfree.php",
data: { type: "get_free", getfree:getfree }
})
.done(function( msg ) {
console.log(msg);
getfree = msg;
})
.fail(function() {
alert( "error" );
});
return getfree;
}
function formsend (e) {
e.preventDefault();
let error = formvalidate(form)
}
public function searchGoods($priceID) {
$varName = 'valuePrice' . $priceID;
$this->goodsList[$priceID] = SiteParserService::getByKod($this->{$varName});
}
$order->numb_type[$key] = $value;
$key
?$order->numb_type = $value;
? $array1 = [
"ID" => 42,
"field" => "Earth",
];
$array2 = [
"ID" => 42,
"field" => "Mars",
];