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
|
<?php
|
||||||
// Simuloi logo upload suoraan palvelimella
|
// Testaa koko upload-flow ilman autentikaatiota
|
||||||
ini_set('display_errors', '1');
|
ini_set('display_errors', '1');
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
header('Content-Type: text/plain');
|
header('Content-Type: text/plain; charset=utf-8');
|
||||||
|
|
||||||
require_once __DIR__ . '/db.php';
|
require_once __DIR__ . '/db.php';
|
||||||
|
|
||||||
// Testaa kirjoitusoikeus
|
define('DATA_DIR', __DIR__ . '/data');
|
||||||
$compDir = __DIR__ . '/data/companies/web1';
|
|
||||||
echo "Kansio $compDir:\n";
|
|
||||||
echo " exists: " . (file_exists($compDir) ? 'kyllä' : 'ei') . "\n";
|
|
||||||
|
|
||||||
if (!file_exists($compDir)) {
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['logo'])) {
|
||||||
$ok = @mkdir($compDir, 0755, true);
|
$companyId = $_POST['company_id'] ?? 'web1';
|
||||||
echo " mkdir: " . ($ok ? 'OK' : 'EPÄONNISTUI: ' . error_get_last()['message'] ?? 'tuntematon') . "\n";
|
$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;
|
||||||
}
|
}
|
||||||
|
|
||||||
echo " writable: " . (is_writable($compDir) ? 'kyllä' : 'EI') . "\n";
|
$finfo = finfo_open(FILEINFO_MIME_TYPE);
|
||||||
|
$detectedType = finfo_file($finfo, $file['tmp_name']);
|
||||||
|
finfo_close($finfo);
|
||||||
|
echo " detected mime: $detectedType\n\n";
|
||||||
|
|
||||||
// Testaa data/ kansion oikeudet
|
$extMap = ['image/png' => 'png', 'image/jpeg' => 'jpg', 'image/svg+xml' => 'svg', 'image/webp' => 'webp'];
|
||||||
echo "\ndata/ kansio:\n";
|
$ext = $extMap[$detectedType] ?? 'unknown';
|
||||||
echo " exists: " . (file_exists(__DIR__ . '/data') ? 'kyllä' : 'ei') . "\n";
|
$newFilename = 'logo.' . $ext;
|
||||||
echo " writable: " . (is_writable(__DIR__ . '/data') ? 'kyllä' : 'EI') . "\n";
|
|
||||||
|
|
||||||
$dataCompanies = __DIR__ . '/data/companies';
|
$compDir = DATA_DIR . '/companies/' . $companyId;
|
||||||
echo "\ndata/companies/ kansio:\n";
|
if (!file_exists($compDir)) mkdir($compDir, 0755, true);
|
||||||
echo " exists: " . (file_exists($dataCompanies) ? 'kyllä' : 'ei') . "\n";
|
|
||||||
echo " writable: " . (is_writable($dataCompanies) ? 'kyllä' : 'EI') . "\n";
|
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>';
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user