This commit is contained in:
Francesco Picone
2025-12-06 18:50:57 +01:00
parent 86f4774df2
commit ca86649914
8 changed files with 219 additions and 2 deletions

33
.gitignore vendored Normal file
View File

@@ -0,0 +1,33 @@
# Vendor e dipendenze
/vendor/
composer.lock
# File caricati
/uploads/lessons/**/*.mp4
/uploads/lessons/**/*.webm
/uploads/lessons/**/*.ogg
/uploads/lessons/**/*.mov
/uploads/images/*.jpg
/uploads/images/*.png
# Configurazione (contiene password)
# includes/config.php
# File di debug
test_password.php
test_email.php
# Log
*.log
# OS
.DS_Store
Thumbs.db
desktop.ini
# IDE
.vscode/
.idea/
*.swp
*.swo
*~

View File

@@ -141,7 +141,32 @@ define('PAYPAL_CLIENT_ID', 'il-tuo-client-id-sandbox');
define('PAYPAL_SECRET', 'il-tuo-secret-sandbox'); define('PAYPAL_SECRET', 'il-tuo-secret-sandbox');
``` ```
### Passo 4: Configura i Permessi (Linux/Mac) ### Passo 4: Installa getID3 (Opzionale - per durata video automatica)
La piattaforma può estrarre automaticamente la durata dei video caricati usando getID3.
#### Metodo 1: Con Composer (raccomandato)
```bash
composer install
```
#### Metodo 2: Script Automatico
```bash
# Linux/Mac
bash install_getid3.sh
# Windows PowerShell
.\install_getid3.ps1
```
#### Metodo 3: Manuale
1. Scarica getID3 da [GitHub](https://github.com/JamesHeinrich/getID3/releases)
2. Estrai in `vendor/getid3/getid3/`
3. Verifica che esista il file `vendor/getid3/getid3/getid3.php`
**Nota:** Se getID3 non è disponibile, la piattaforma proverà ad usare ffmpeg/ffprobe. Se anche questi non sono disponibili, dovrai inserire manualmente la durata.
### Passo 5: Configura i Permessi (Linux/Mac)
```bash ```bash
# Rendi scrivibile la cartella uploads e sottocartelle # Rendi scrivibile la cartella uploads e sottocartelle
chmod -R 755 uploads/ chmod -R 755 uploads/
@@ -150,7 +175,9 @@ chmod -R 755 uploads/lessons/pay/
chmod -R 755 uploads/images/ chmod -R 755 uploads/images/
``` ```
### Passo 5: Avvia il Server **Nota:** Le cartelle `demo/` e `pay/` vengono create automaticamente all'upload se non esistono.
### Passo 6: Avvia il Server
#### Con PHP Built-in (per sviluppo) #### Con PHP Built-in (per sviluppo)
```bash ```bash
cd pilates-platform cd pilates-platform
@@ -426,6 +453,15 @@ Crea `.htaccess` nella cartella `includes/`:
- Controlla `upload_max_filesize` e `post_max_size` in `php.ini` - Controlla `upload_max_filesize` e `post_max_size` in `php.ini`
- Verifica che la cartella `uploads/lessons/` sia scrivibile - Verifica che la cartella `uploads/lessons/` sia scrivibile
- Assicurati che il formato sia supportato (MP4, WebM, OGG, MOV) - Assicurati che il formato sia supportato (MP4, WebM, OGG, MOV)
- Le cartelle `demo/` e `pay/` vengono create automaticamente se non esistono
### La durata video non viene rilevata
- Installa getID3 per estrazione automatica durata:
- Con Composer: `composer install`
- Manualmente (Linux/Mac): `bash install_getid3.sh`
- Manualmente (Windows): `.\install_getid3.ps1`
- Oppure usa ffmpeg/ffprobe (già installato sulla maggior parte dei server)
- Se non disponibile, inserisci manualmente la durata nel form
### PayPal non funziona ### PayPal non funziona
- Verifica Client ID e Secret - Verifica Client ID e Secret

View File

@@ -36,6 +36,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if ($type === 'video' && $video_platform === 'local' && isset($_FILES['video_file']) && $_FILES['video_file']['error'] === UPLOAD_ERR_OK) { if ($type === 'video' && $video_platform === 'local' && isset($_FILES['video_file']) && $_FILES['video_file']['error'] === UPLOAD_ERR_OK) {
$upload_dir = $is_demo ? '../uploads/lessons/demo/' : '../uploads/lessons/pay/'; $upload_dir = $is_demo ? '../uploads/lessons/demo/' : '../uploads/lessons/pay/';
// Crea le cartelle se non esistono
if (!is_dir($upload_dir)) {
mkdir($upload_dir, 0755, true);
}
// Crea nome file sicuro // Crea nome file sicuro
$file_extension = strtolower(pathinfo($_FILES['video_file']['name'], PATHINFO_EXTENSION)); $file_extension = strtolower(pathinfo($_FILES['video_file']['name'], PATHINFO_EXTENSION));
$allowed_extensions = ['mp4', 'webm', 'ogg', 'mov']; $allowed_extensions = ['mp4', 'webm', 'ogg', 'mov'];
@@ -49,6 +54,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (move_uploaded_file($_FILES['video_file']['tmp_name'], $upload_path)) { if (move_uploaded_file($_FILES['video_file']['tmp_name'], $upload_path)) {
// Imposta il percorso relativo per il database // Imposta il percorso relativo per il database
$video_url = '/uploads/lessons/' . ($is_demo ? 'demo' : 'pay') . '/' . $file_name; $video_url = '/uploads/lessons/' . ($is_demo ? 'demo' : 'pay') . '/' . $file_name;
// Estrai durata automaticamente se non specificata
if (empty($duration)) {
$duration = get_video_duration($upload_path);
}
} else { } else {
$error = 'Errore durante il caricamento del file'; $error = 'Errore durante il caricamento del file';
} }

View File

@@ -65,6 +65,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if ($type === 'video' && $video_platform === 'local' && isset($_FILES['video_file']) && $_FILES['video_file']['error'] === UPLOAD_ERR_OK) { if ($type === 'video' && $video_platform === 'local' && isset($_FILES['video_file']) && $_FILES['video_file']['error'] === UPLOAD_ERR_OK) {
$upload_dir = $is_demo ? '../uploads/lessons/demo/' : '../uploads/lessons/pay/'; $upload_dir = $is_demo ? '../uploads/lessons/demo/' : '../uploads/lessons/pay/';
// Crea le cartelle se non esistono
if (!is_dir($upload_dir)) {
mkdir($upload_dir, 0755, true);
}
// Crea nome file sicuro // Crea nome file sicuro
$file_extension = strtolower(pathinfo($_FILES['video_file']['name'], PATHINFO_EXTENSION)); $file_extension = strtolower(pathinfo($_FILES['video_file']['name'], PATHINFO_EXTENSION));
$allowed_extensions = ['mp4', 'webm', 'ogg', 'mov']; $allowed_extensions = ['mp4', 'webm', 'ogg', 'mov'];
@@ -82,6 +87,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
} }
// Imposta il nuovo percorso // Imposta il nuovo percorso
$video_url = '/uploads/lessons/' . ($is_demo ? 'demo' : 'pay') . '/' . $file_name; $video_url = '/uploads/lessons/' . ($is_demo ? 'demo' : 'pay') . '/' . $file_name;
// Estrai durata automaticamente se non specificata
if (empty($duration)) {
$duration = get_video_duration($upload_path);
}
} else { } else {
$error = 'Errore durante il caricamento del file'; $error = 'Errore durante il caricamento del file';
} }

14
composer.json Normal file
View File

@@ -0,0 +1,14 @@
{
"name": "pilates-platform",
"description": "Piattaforma Pilates per vendita videolezioni",
"type": "project",
"require": {
"php": ">=7.4",
"james-heinrich/getid3": "^1.9"
},
"autoload": {
"files": [
"includes/functions.php"
]
}
}

View File

@@ -669,4 +669,67 @@ function redirect($url) {
exit; exit;
} }
/**
* Estrae la durata di un video in minuti
*
* @param string $file_path Percorso del file video
* @return int|null Durata in minuti o null se non rilevabile
*/
function get_video_duration($file_path) {
// Metodo 1: Usa getID3 se disponibile
if (file_exists(__DIR__ . '/../vendor/getid3/getid3/getid3.php')) {
require_once __DIR__ . '/../vendor/getid3/getid3/getid3.php';
try {
$getID3 = new getID3();
$file_info = $getID3->analyze($file_path);
if (isset($file_info['playtime_seconds'])) {
return (int) ceil($file_info['playtime_seconds'] / 60);
}
} catch (Exception $e) {
// Continua con altri metodi
}
}
// Metodo 2: Usa ffprobe se disponibile
if (function_exists('shell_exec') && !in_array('shell_exec', explode(',', ini_get('disable_functions')))) {
$ffprobe_commands = [
'ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 ' . escapeshellarg($file_path),
'/usr/bin/ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 ' . escapeshellarg($file_path),
'/usr/local/bin/ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 ' . escapeshellarg($file_path)
];
foreach ($ffprobe_commands as $cmd) {
$output = @shell_exec($cmd . ' 2>&1');
if ($output && is_numeric(trim($output))) {
$seconds = (float) trim($output);
return (int) ceil($seconds / 60);
}
}
}
// Metodo 3: Usa ffmpeg se disponibile
if (function_exists('shell_exec') && !in_array('shell_exec', explode(',', ini_get('disable_functions')))) {
$ffmpeg_commands = [
'ffmpeg -i ' . escapeshellarg($file_path) . ' 2>&1',
'/usr/bin/ffmpeg -i ' . escapeshellarg($file_path) . ' 2>&1',
'/usr/local/bin/ffmpeg -i ' . escapeshellarg($file_path) . ' 2>&1'
];
foreach ($ffmpeg_commands as $cmd) {
$output = @shell_exec($cmd);
if ($output && preg_match('/Duration: (\d{2}):(\d{2}):(\d{2})/', $output, $matches)) {
$hours = (int) $matches[1];
$minutes = (int) $matches[2];
$seconds = (int) $matches[3];
return $hours * 60 + $minutes + (int) ceil($seconds / 60);
}
}
}
// Nessun metodo funzionante
return null;
}
?> ?>

31
install_getid3.ps1 Normal file
View File

@@ -0,0 +1,31 @@
# Script PowerShell per installare getID3 manualmente
Write-Host "Installazione getID3..." -ForegroundColor Green
# Crea cartella vendor se non esiste
New-Item -ItemType Directory -Force -Path "vendor\getid3" | Out-Null
# URL del download
$url = "https://github.com/JamesHeinrich/getID3/archive/refs/tags/v1.9.23.zip"
$zipFile = "vendor\getid3\getid3.zip"
# Scarica getID3
Write-Host "Download in corso..." -ForegroundColor Yellow
Invoke-WebRequest -Uri $url -OutFile $zipFile
# Estrai
Write-Host "Estrazione file..." -ForegroundColor Yellow
Expand-Archive -Path $zipFile -DestinationPath "vendor\getid3\temp" -Force
# Sposta i file nella posizione corretta
Get-ChildItem "vendor\getid3\temp\getID3-*" | Get-ChildItem | Move-Item -Destination "vendor\getid3" -Force
# Pulisci
Remove-Item -Path "vendor\getid3\temp" -Recurse -Force
Remove-Item -Path $zipFile -Force
Write-Host ""
Write-Host "✅ getID3 installato con successo!" -ForegroundColor Green
Write-Host ""
Write-Host "Nota: Se hai Composer disponibile, puoi usare invece:" -ForegroundColor Cyan
Write-Host " composer install" -ForegroundColor White

20
install_getid3.sh Normal file
View File

@@ -0,0 +1,20 @@
#!/bin/bash
# Script per installare getID3 manualmente
echo "Installazione getID3..."
# Crea cartella vendor se non esiste
mkdir -p vendor/getid3
# Scarica getID3
cd vendor/getid3
wget https://github.com/JamesHeinrich/getID3/archive/refs/tags/v1.9.23.tar.gz -O getid3.tar.gz
# Estrai
tar -xzf getid3.tar.gz --strip-components=1
rm getid3.tar.gz
echo "✅ getID3 installato con successo!"
echo ""
echo "Nota: Se hai Composer disponibile, puoi usare invece:"
echo " composer install"