<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_FILES['file'])) {
    $uploadDir = 'uploads/';
    if (!is_dir($uploadDir)) mkdir($uploadDir, 0777, true);
    
    $fileTmp = $_FILES['file']['tmp_name'];
    $fileName = basename($_FILES['file']['name']);
    $targetPath = $uploadDir . $fileName;

    if (move_uploaded_file($fileTmp, $targetPath)) {
        echo json_encode(['status' => 'success', 'url' => 'https://music.c-e-g.ir/uploader/' . $fileName]);
    } else {
        echo json_encode(['status' => 'error', 'message' => 'Upload failed.']);
    }
} else {
    echo json_encode(['status' => 'error', 'message' => 'No file sent.']);
}
?>
