Skip to content

Commit

Permalink
Edit
Browse files Browse the repository at this point in the history
Added on page edit of links and config
add icon upload
  • Loading branch information
mwlistscom committed Jul 30, 2024
1 parent 338020f commit 3eef186
Show file tree
Hide file tree
Showing 10 changed files with 795 additions and 456 deletions.
Binary file removed Emby.png
Binary file not shown.
6 changes: 0 additions & 6 deletions README.md

This file was deleted.

Binary file removed Radarr.png
Binary file not shown.
Binary file removed Sonarr.png
Binary file not shown.
1,109 changes: 678 additions & 431 deletions index.php

Large diffs are not rendered by default.

19 changes: 0 additions & 19 deletions jelly.svg

This file was deleted.

14 changes: 14 additions & 0 deletions save_config.php
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]);
?>
9 changes: 9 additions & 0 deletions save_links.php
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.';
}
?>
45 changes: 45 additions & 0 deletions update_icon.php
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]);
}
}
?>
49 changes: 49 additions & 0 deletions upload_icon.php
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);
?>

0 comments on commit 3eef186

Please sign in to comment.