-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added on page edit of links and config add icon upload
- Loading branch information
1 parent
338020f
commit 3eef186
Showing
10 changed files
with
795 additions
and
456 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
// Read the posted JSON data | ||
$configData = json_decode(file_get_contents('php://input'), true); | ||
|
||
// Generate the config.php content | ||
$configContent = "<?php\n"; | ||
foreach ($configData as $key => $value) { | ||
$configContent .= "\$$key = \"" . addslashes($value) . "\";\n"; | ||
} | ||
|
||
// Save the config.php file | ||
file_put_contents('config.php', $configContent); | ||
echo json_encode(['success' => true]); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
$data = json_decode(file_get_contents('php://input'), true); | ||
if ($data && isset($data['Links'])) { | ||
file_put_contents('links.json', json_encode($data, JSON_PRETTY_PRINT)); | ||
echo 'Links saved successfully!'; | ||
} else { | ||
echo 'Failed to save links.'; | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
if (!file_exists('icons')) { | ||
mkdir('icons', 0777, true); | ||
} | ||
|
||
$targetDir = "icons/"; | ||
$targetFile = $targetDir . basename($_FILES["icon_file"]["name"]); | ||
$uploadOk = 1; | ||
$imageFileType = strtolower(pathinfo($targetFile, PATHINFO_EXTENSION)); | ||
|
||
// Check if image file is a actual image or fake image | ||
$check = getimagesize($_FILES["icon_file"]["tmp_name"]); | ||
if ($check !== false) { | ||
$uploadOk = 1; | ||
} else { | ||
$uploadOk = 0; | ||
} | ||
|
||
// Check if file already exists | ||
if (file_exists($targetFile)) { | ||
$uploadOk = 0; | ||
} | ||
|
||
// Check file size | ||
if ($_FILES["icon_file"]["size"] > 500000) { | ||
$uploadOk = 0; | ||
} | ||
|
||
// Allow certain file formats | ||
if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif") { | ||
$uploadOk = 0; | ||
} | ||
|
||
// Check if $uploadOk is set to 0 by an error | ||
if ($uploadOk == 0) { | ||
echo json_encode(['success' => false]); | ||
// if everything is ok, try to upload file | ||
} else { | ||
if (move_uploaded_file($_FILES["icon_file"]["tmp_name"], $targetFile)) { | ||
echo json_encode(['success' => true, 'filename' => basename($_FILES["icon_file"]["name"])]); | ||
} else { | ||
echo json_encode(['success' => false]); | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
$response = ['success' => false, 'filename' => '']; | ||
|
||
if (isset($_FILES['icon_file']) && $_FILES['icon_file']['error'] == 0) { | ||
$targetDir = "icons/"; | ||
|
||
// Create the icons directory if it doesn't exist | ||
if (!is_dir($targetDir)) { | ||
mkdir($targetDir, 0755, true); | ||
} | ||
|
||
$fileName = basename($_FILES['icon_file']['name']); | ||
$targetFile = $targetDir . $fileName; | ||
$imageFileType = strtolower(pathinfo($targetFile, PATHINFO_EXTENSION)); | ||
|
||
// Allowed file types | ||
$allowedTypes = ['jpg', 'jpeg', 'png', 'gif']; | ||
// Limit file size to 5MB | ||
$maxFileSize = 5 * 1024 * 1024; // 5MB | ||
|
||
// Check if the file is an allowed image type | ||
$check = getimagesize($_FILES['icon_file']['tmp_name']); | ||
if ($check !== false && in_array($imageFileType, $allowedTypes) && $_FILES['icon_file']['size'] <= $maxFileSize) { | ||
// Generate a unique file name if a file with the same name exists | ||
$uniqueFileName = $fileName; | ||
$counter = 1; | ||
while (file_exists($targetDir . $uniqueFileName)) { | ||
$uniqueFileName = pathinfo($fileName, PATHINFO_FILENAME) . '_' . $counter . '.' . $imageFileType; | ||
$counter++; | ||
} | ||
$targetFile = $targetDir . $uniqueFileName; | ||
|
||
if (move_uploaded_file($_FILES['icon_file']['tmp_name'], $targetFile)) { | ||
$response['success'] = true; | ||
$response['filename'] = $uniqueFileName; | ||
} else { | ||
$response['error'] = 'Error uploading the file.'; | ||
} | ||
} else { | ||
$response['error'] = 'Invalid file type or file too large.'; | ||
} | ||
} else { | ||
$response['error'] = 'No file uploaded or upload error.'; | ||
} | ||
|
||
header('Content-Type: application/json'); | ||
echo json_encode($response); | ||
?> | ||
|