<?php
// Enable error reporting
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Set maximum execution time to 5 minutes
ini_set('max_execution_time', 300);
// Start session
session_start();
// Function to create directory if it doesn't exist
function createDir($dir) {
if (!file_exists($dir)) {
mkdir($dir, 0777, true);
}
}
// Function to download an image from a URL
function downloadImage($url, $file_path) {
// Check if file already exists
if (file_exists($file_path)) {
return true;
}
// Create directory if it doesn't exist
$dir = dirname($file_path);
createDir($dir);
// Download image
$image_data = @file_get_contents($url);
if ($image_data === false) {
return false;
}
// Save image
return file_put_contents($file_path, $image_data) !== false;
}
// Create directories
createDir('assets/images/logo');
createDir('assets/images/hero');
createDir('assets/images/courses');
createDir('assets/images/team');
createDir('assets/images/testimonials');
createDir('assets/images/blog');
createDir('assets/images/profile');
// Define images to download
$images = [
// Logo
[
'url' => 'https://placehold.co/200x60/4e73df/ffffff?text=LMS+Logo',
'file_path' => 'assets/images/logo.png'
],
// Hero images
[
'url' => 'https://placehold.co/1920x600/343a40/ffffff?text=Hero+Image+1',
'file_path' => 'assets/images/hero/hero1.jpg'
],
[
'url' => 'https://placehold.co/800x600/6c757d/ffffff?text=Hero+Image+2',
'file_path' => 'assets/images/hero/hero2.jpg'
],
// Course images
[
'url' => 'https://placehold.co/400x200/4e73df/ffffff?text=Web+Development',
'file_path' => 'assets/images/courses/1.jpg'
],
[
'url' => 'https://placehold.co/400x200/1cc88a/ffffff?text=Data+Science',
'file_path' => 'assets/images/courses/2.jpg'
],
[
'url' => 'https://placehold.co/400x200/36b9cc/ffffff?text=Digital+Marketing',
'file_path' => 'assets/images/courses/3.jpg'
],
[
'url' => 'https://placehold.co/400x200/f6c23e/ffffff?text=Graphic+Design',
'file_path' => 'assets/images/courses/4.jpg'
],
// Team images
[
'url' => 'https://placehold.co/300x300/4e73df/ffffff?text=Team+Member+1',
'file_path' => 'assets/images/team/team1.jpg'
],
[
'url' => 'https://placehold.co/300x300/1cc88a/ffffff?text=Team+Member+2',
'file_path' => 'assets/images/team/team2.jpg'
],
[
'url' => 'https://placehold.co/300x300/36b9cc/ffffff?text=Team+Member+3',
'file_path' => 'assets/images/team/team3.jpg'
],
// Testimonial images
[
'url' => 'https://placehold.co/100x100/4e73df/ffffff?text=User+1',
'file_path' => 'assets/images/testimonials/user1.jpg'
],
[
'url' => 'https://placehold.co/100x100/1cc88a/ffffff?text=User+2',
'file_path' => 'assets/images/testimonials/user2.jpg'
],
[
'url' => 'https://placehold.co/100x100/36b9cc/ffffff?text=User+3',
'file_path' => 'assets/images/testimonials/user3.jpg'
],
// Blog images
[
'url' => 'https://placehold.co/800x400/4e73df/ffffff?text=Blog+Post+1',
'file_path' => 'assets/images/blog/post1.jpg'
],
[
'url' => 'https://placehold.co/800x400/1cc88a/ffffff?text=Blog+Post+2',
'file_path' => 'assets/images/blog/post2.jpg'
],
[
'url' => 'https://placehold.co/800x400/36b9cc/ffffff?text=Blog+Post+3',
'file_path' => 'assets/images/blog/post3.jpg'
],
// Default profile image
[
'url' => 'https://placehold.co/200x200/4e73df/ffffff?text=Profile',
'file_path' => 'assets/images/profile/default.jpg'
]
];
// Download images
$success_count = 0;
$error_count = 0;
echo '<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Downloading Placeholder Images</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
line-height: 1.6;
}
h1, h2 {
color: #4e73df;
}
.success {
color: green;
}
.error {
color: red;
}
.btn {
display: inline-block;
padding: 10px 20px;
background-color: #4e73df;
color: white;
text-decoration: none;
border-radius: 5px;
margin-top: 20px;
}
.btn:hover {
background-color: #2e59d9;
}
</style>
</head>
<body>
<h1>Downloading Placeholder Images</h1>';
foreach ($images as $image) {
echo '<p>Downloading image: ' . $image['file_path'] . ' ... ';
try {
if (downloadImage($image['url'], $image['file_path'])) {
echo '<span class="success">Success</span></p>';
$success_count++;
} else {
echo '<span class="error">Failed</span></p>';
$error_count++;
}
} catch (Exception $e) {
echo '<span class="error">Error: ' . $e->getMessage() . '</span></p>';
$error_count++;
}
// Flush output to show progress
flush();
ob_flush();
// Add a small delay to prevent overwhelming the server
usleep(100000); // 0.1 second
}
// Create CSS file with image references
$css_content = "/* Generated image references */\n\n";
$css_content .= ".course-1 { background-image: url('../images/courses/1.jpg'); }\n";
$css_content .= ".course-2 { background-image: url('../images/courses/2.jpg'); }\n";
$css_content .= ".course-3 { background-image: url('../images/courses/3.jpg'); }\n";
$css_content .= ".course-4 { background-image: url('../images/courses/4.jpg'); }\n";
// Create directory if it doesn't exist
createDir('assets/css');
// Write CSS file
file_put_contents('assets/css/images.css', $css_content);
echo '<h2>Summary</h2>';
echo '<p>Total images: ' . count($images) . '</p>';
echo '<p>Successfully downloaded: ' . $success_count . '</p>';
echo '<p>Failed: ' . $error_count . '</p>';
echo '<h2>Next Steps</h2>';
echo '<ol>';
echo '<li>The CSS file has been created at <code>assets/css/images.css</code></li>';
echo '<li>Make sure to include it in your HTML: <code><link rel="stylesheet" href="assets/css/images.css"></code></li>';
echo '</ol>';
echo '<p><a href="fixed_index.php" class="btn">View Website</a></p>';
echo '<p><a href="login.php" class="btn">Go to Login</a></p>';
echo '</body></html>';
?>