Server : LiteSpeed System : Linux us-phx-web1202.main-hosting.eu 4.18.0-553.84.1.lve.el8.x86_64 #1 SMP Tue Nov 25 18:33:03 UTC 2025 x86_64 User : u615232177 ( 615232177) PHP Version : 8.1.33 Disable Function : NONE Directory : /home/u615232177/domains/ellexsleevesapartments.com/public_html/admin1249/ |
<?php session_start();
$page_name = basename($_SERVER['PHP_SELF']);
include("headerstrict.php"); ?>
<title><?php echo $company_name; ?>, Admin, Images</title>
<?php
function getPhpFiles($dir) {
$rii = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS),
RecursiveIteratorIterator::SELF_FIRST
);
$files = [];
foreach ($rii as $file) {
if ($file->isFile() && pathinfo($file, PATHINFO_EXTENSION) === 'php') {
$files[] = $file->getPathname();
}
}
return $files;
}
?>
<!-- ======= Breadcrumbs ======= -->
<section id="breadcrumbs" class="breadcrumbs">
<div class="container"> </div>
</section>
<!-- End Breadcrumbs -->
<!-- ======= Contact Section ======= -->
<section id="contact" class="contact inner-page">
<div class="container" data-aos="fade-up">
<div class="section-title">
<h2>Other Images</h2>
<p></p>
</div>
<div class='row'>
<?php
$stmt = $con -> prepare('SELECT * FROM general_images ORDER by photo_order');
$stmt -> execute();
$stmt -> store_result();
$stmt -> bind_result($id,$po,$picture,$file_name);
$numrows = $stmt -> num_rows();
if($numrows > 0){
while ($stmt -> fetch()) {
echo"
<div class='col-md-4'>
<form action='";?><?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?><?php echo"' method='post'class='php-email-form1'enctype='multipart/form-data'>
<div class='form-row'>
<div class='form-group col-md-12'> <h3>$picture</h3>
<img style='width:100%;border-radius:5px;height:300px;object-fit:cover;' src='../site_img/general/$file_name' class='img-fluid' alt=''>
<input type='file' name='fileField$id' class='form-control'/>
</div>
</div>
<div class='text-center'>
<a class='btn btn-primary' href='../site_img/general/$file_name'>View</a>
<button type='submit' name='update$id'>Update</button>
</div>
</form>
</div>
";
if (isset($_POST["update$id"])) {
if( ($_FILES["fileField$id"]["type"]=="") == false ){
unlink("../site_img/general/$file_name");
$random_id = substr(md5(rand()), 0, 10);
$extension = pathinfo($_FILES["fileField$id"]["name"], PATHINFO_EXTENSION);
move_uploaded_file( $_FILES["fileField$id"]['tmp_name'], "../site_img/general/$random_id.$extension");
$picture ="$random_id.$extension";
}
//replace occurences in front end
$replacements = [$file_name => $picture];
$foldersToScan = ['../'];
$allPhpFiles = [];
foreach ($foldersToScan as $folder) {
$allPhpFiles = array_merge($allPhpFiles, getPhpFiles($folder));
}
// Replace image names in each PHP file
foreach ($allPhpFiles as $file) {
$content = file_get_contents($file);
foreach ($replacements as $search => $replace) {
$content = str_replace($search, $replace, $content);
}
file_put_contents($file, $content);
}
$stmt = $con -> prepare('UPDATE general_images SET size = ? WHERE id = ?');
$stmt -> bind_param('si', $picture,$id);
$stmt -> execute();
//create a session to verify it's coming from here
$_SESSION["action"] = "true";
$message="Update was successfully done.";
echo "<meta http-equiv=\"refresh\" content=\"0; url=success.php?u=$page_name&m=$message\">";
}
}
}
?>
</div>
</div>
</section><!-- End Contact Section -->
<?php include("footer.php"); ?>