C:\xampp\htdocs\kptv\uploader\upload.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
header
('Content-Type: application/json; charset=UTF-8');

// Log file path
$logFile __DIR__ '/upload.log';

// Path configurare
$uploadDir realpath(__DIR__ '/../images/uploads');
$uploadUrl '/images/uploads/';

if (!
$uploadDir) {
    
file_put_contents($logFiledate('Y-m-d H:i:s') . " - ERROR: Upload dir does not exist.\n"FILE_APPEND);
    echo 
json_encode(['uploaded' => 0'error' => ['message' => 'Server error: upload path invalid']]);
    exit;
}

// Test dacă folderul e scriabil
if (!is_writable($uploadDir)) {
    
file_put_contents($logFiledate('Y-m-d H:i:s') . " - ERROR: Upload dir not writable: $uploadDir\n"FILE_APPEND);
    echo 
json_encode(['uploaded' => 0'error' => ['message' => 'Upload folder not writable']]);
    exit;
}

// Procesare upload
if (isset($_FILES['upload'])) {
    
$file $_FILES['upload'];
    
$fileName basename($file['name']);
    
$targetPath $uploadDir DIRECTORY_SEPARATOR $fileName;

    
// Verificare existență fișier temporar
    
if (!file_exists($file['tmp_name'])) {
        
file_put_contents($logFiledate('Y-m-d H:i:s') . " - ERROR: Temporary file does not exist.\n"FILE_APPEND);
        echo 
json_encode(['uploaded' => 0'error' => ['message' => 'Temp file not found']]);
        exit;
    }

    
// Încercare mutare fișier
    
if (move_uploaded_file($file['tmp_name'], $targetPath)) {
        
$fileUrl $uploadUrl '/' rawurlencode($fileName);
        echo 
json_encode([
            
'uploaded' => 1,
            
'fileName' => $fileName,
            
'url' => $fileUrl
        
]);
    } else {
        
file_put_contents($logFiledate('Y-m-d H:i:s') . " - ERROR: move_uploaded_file failed. tmp_name: {$file['tmp_name']}, target: $targetPath\n"FILE_APPEND);
        echo 
json_encode([
            
'uploaded' => 0,
            
'error' => ['message' => 'Upload failed (cannot move file)']
        ]);
    }
} else {
    
file_put_contents($logFiledate('Y-m-d H:i:s') . " - ERROR: No file in request.\n"FILE_APPEND);
    echo 
json_encode([
        
'uploaded' => 0,
        
'error' => ['message' => 'No file received']
    ]);
}
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586