temp: full logo upload test with form
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,29 +1,69 @@
|
||||
<?php
|
||||
// Simuloi logo upload suoraan palvelimella
|
||||
// Testaa koko upload-flow ilman autentikaatiota
|
||||
ini_set('display_errors', '1');
|
||||
error_reporting(E_ALL);
|
||||
header('Content-Type: text/plain');
|
||||
header('Content-Type: text/plain; charset=utf-8');
|
||||
|
||||
require_once __DIR__ . '/db.php';
|
||||
|
||||
// Testaa kirjoitusoikeus
|
||||
$compDir = __DIR__ . '/data/companies/web1';
|
||||
echo "Kansio $compDir:\n";
|
||||
echo " exists: " . (file_exists($compDir) ? 'kyllä' : 'ei') . "\n";
|
||||
define('DATA_DIR', __DIR__ . '/data');
|
||||
|
||||
if (!file_exists($compDir)) {
|
||||
$ok = @mkdir($compDir, 0755, true);
|
||||
echo " mkdir: " . ($ok ? 'OK' : 'EPÄONNISTUI: ' . error_get_last()['message'] ?? 'tuntematon') . "\n";
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['logo'])) {
|
||||
$companyId = $_POST['company_id'] ?? 'web1';
|
||||
$file = $_FILES['logo'];
|
||||
|
||||
echo "Upload tiedot:\n";
|
||||
echo " company_id: $companyId\n";
|
||||
echo " name: {$file['name']}\n";
|
||||
echo " type: {$file['type']}\n";
|
||||
echo " size: {$file['size']}\n";
|
||||
echo " error: {$file['error']}\n";
|
||||
echo " tmp_name: {$file['tmp_name']}\n\n";
|
||||
|
||||
if ($file['error'] !== UPLOAD_ERR_OK) {
|
||||
echo "❌ Upload error: {$file['error']}\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
$finfo = finfo_open(FILEINFO_MIME_TYPE);
|
||||
$detectedType = finfo_file($finfo, $file['tmp_name']);
|
||||
finfo_close($finfo);
|
||||
echo " detected mime: $detectedType\n\n";
|
||||
|
||||
$extMap = ['image/png' => 'png', 'image/jpeg' => 'jpg', 'image/svg+xml' => 'svg', 'image/webp' => 'webp'];
|
||||
$ext = $extMap[$detectedType] ?? 'unknown';
|
||||
$newFilename = 'logo.' . $ext;
|
||||
|
||||
$compDir = DATA_DIR . '/companies/' . $companyId;
|
||||
if (!file_exists($compDir)) mkdir($compDir, 0755, true);
|
||||
|
||||
echo "Tallenna: $compDir/$newFilename\n";
|
||||
$ok = move_uploaded_file($file['tmp_name'], $compDir . '/' . $newFilename);
|
||||
echo $ok ? "✅ Tiedosto tallennettu!\n" : "❌ move_uploaded_file epäonnistui\n";
|
||||
|
||||
if ($ok) {
|
||||
$companies = dbLoadCompanies();
|
||||
foreach ($companies as $comp) {
|
||||
if ($comp['id'] === $companyId) {
|
||||
$comp['logo_file'] = $newFilename;
|
||||
try {
|
||||
dbSaveCompany($comp);
|
||||
echo "✅ Kanta päivitetty (logo_file = $newFilename)\n";
|
||||
} catch (Throwable $e) {
|
||||
echo "❌ DB virhe: " . $e->getMessage() . "\n";
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
echo "\nJSON response olisi:\n";
|
||||
echo json_encode(['success' => true, 'logo_file' => $newFilename, 'logo_url' => "api.php?action=company_logo&company_id=" . urlencode($companyId)]);
|
||||
}
|
||||
} else {
|
||||
echo "Käytä POST-lomaketta:\n\n";
|
||||
header('Content-Type: text/html; charset=utf-8');
|
||||
echo '<form method="POST" enctype="multipart/form-data">
|
||||
<input type="hidden" name="company_id" value="web1">
|
||||
<input type="file" name="logo" accept="image/*">
|
||||
<button type="submit">Upload logo</button>
|
||||
</form>';
|
||||
}
|
||||
|
||||
echo " writable: " . (is_writable($compDir) ? 'kyllä' : 'EI') . "\n";
|
||||
|
||||
// Testaa data/ kansion oikeudet
|
||||
echo "\ndata/ kansio:\n";
|
||||
echo " exists: " . (file_exists(__DIR__ . '/data') ? 'kyllä' : 'ei') . "\n";
|
||||
echo " writable: " . (is_writable(__DIR__ . '/data') ? 'kyllä' : 'EI') . "\n";
|
||||
|
||||
$dataCompanies = __DIR__ . '/data/companies';
|
||||
echo "\ndata/companies/ kansio:\n";
|
||||
echo " exists: " . (file_exists($dataCompanies) ? 'kyllä' : 'ei') . "\n";
|
||||
echo " writable: " . (is_writable($dataCompanies) ? 'kyllä' : 'EI') . "\n";
|
||||
|
||||
Reference in New Issue
Block a user