# WhatsApp Media Upload Server

Server PHP standalone untuk upload file attachment ke WhatsApp Cloud API.

## Instalasi

1. **Upload file** ke server PHP terpisah:
   - `upload.php`
   - `.htaccess`
   - Buat folder `uploads/` dengan permission 755

2. **Konfigurasi** di `upload.php`:
```php
// Ganti dengan API key Anda
define('ALLOWED_API_KEYS', [
    'ganti-dengan-api-key-anda',
]);
```

3. **Verifikasi instalasi**:
```bash
curl https://your-domain.com/health
```

## Endpoints

### POST /upload
Upload file dan dapatkan `media_id` dari Meta.

**Headers:**
- `X-API-Key: your-api-key`

**Form Data:**
| Field | Type | Required | Description |
|-------|------|----------|-------------|
| file | File | Ya | File yang diupload |
| access_token | String | Ya | Meta access token |
| phone_number_id | String | Ya | Phone number ID |
| media_type | String | Tidak | image/document/video/audio |

**Response:**
```json
{
  "success": true,
  "media_id": "1234567890",
  "media_type": "image",
  "mime_type": "image/jpeg",
  "filename": "photo.jpg"
}
```

### POST /upload-local
Upload file ke storage lokal (return URL).

**Form Data:**
| Field | Type | Required |
|-------|------|----------|
| file | File | Ya |
| media_type | String | Tidak |

**Response:**
```json
{
  "success": true,
  "file_url": "https://your-domain.com/uploads/abc123.jpg",
  "media_type": "image"
}
```

### GET /health
Health check endpoint.

## Limit File

| Type | Max Size |
|------|----------|
| Image | 5 MB |
| Document | 100 MB |
| Video | 16 MB |
| Audio | 16 MB |

## Contoh Penggunaan (JavaScript)

```javascript
async function uploadFile(file, accessToken, phoneNumberId) {
    const formData = new FormData();
    formData.append('file', file);
    formData.append('access_token', accessToken);
    formData.append('phone_number_id', phoneNumberId);
    
    const response = await fetch('https://your-upload-server.com/upload', {
        method: 'POST',
        headers: {
            'X-API-Key': 'your-api-key'
        },
        body: formData
    });
    
    return await response.json();
}
```
