Файл: pages/admin/import.php
Строк: 58
<?php
/*
** Автор кода: Евгений (rnddev)
** ICQ: 448235
** Email: rnddev@mail.ru
** Skype: rnddev
** Все права принадлежат автору.
** Модефикация и продажа запрещены.
*/
define('ACCESS', TRUE);
define('R', $_SERVER['DOCUMENT_ROOT']);
require_once R.'/system/bootstrap.php';
$tpl->getHead('Импорт файлов');
if($admin) {
    echo '<div class="content">';
    
    if (isset($_POST['submit'])) {
        
        $file = array('mp4' => trim($_POST['file_mp4'])
                      );
        $arr_mp4 = array('mp4', 'MP4');
        
        $ext_mp4 = pathinfo(strtolower($file['mp4']), PATHINFO_EXTENSION);
        
        
        if (empty($file['mp4'])) $error .= 'Вставьте URL на файлы!<br/>';
        elseif (!in_array($ext_mp4, $arr_mp4) ) $error .= 'Запрешенный формат файла!<br/>';
        if (empty($_POST['name'])) $error .= 'Введите имя файла!<br/>';
        
        if (isset($error)) { echo '<div class="error">'.$error.'</div>'; } else {
        
            $filename = PREFIX.time();
            $screen = 'prew_'.$filename.'.png';
            
            copy($file['mp4'], FILES.'/video/'.$filename.'.mp4');
            
            $size_mp4 = filesize(FILES.'/video/'.$filename.'.mp4');
            
            
            $movie = new ffmpeg_movie(FILES.'/video/'.$filename.'.mp4');
            $frame = 15; 
            
            $img_path = FILES.'/screen/'.$screen;
            $image = $movie->getFrame($frame);
            $selfimg = $image->toGDImage(); 
            imagepng($selfimg, $img_path);
            imagedestroy($selfimg);
            
            Main::image_resize($img_path, $img_path, 140, 110, 90); 
            
            $timeleft = $movie->getDuration();
            
            $db->prepare("INSERT INTO video(name, filename, screen, timeleft, size_mp4, date_upload, about) 
                          VALUES (:name, :filename, :screen, :timeleft, :size_mp4, :date_upload, :about)", 
                          array(':name' => $_POST['name'], 
                                ':filename' => $filename,
                                ':screen'    => $screen,
                                ':timeleft' => $timeleft,
                                ':size_mp4' => $size_mp4,
                                
                                ':date_upload'     => time(),
                                ':about'     => $_POST['about']));
            $last_id = $db->lastInsertId();
            foreach ($_POST['option'] as $k=>$v) {
            $db->prepare("INSERT INTO contact(id_video, id_category) VALUES (:id_video, :id_category)", array(':id_video' => $last_id, ':id_category' => $v));
            }
            header('Refresh: 3; url='.$_SERVER['PHP_SELF']);
            echo '<div class="title">Файлы успешно загружены</div>';
        }
    }
    
    echo '<form method="post" action="">',
         'Файл mp4:<br/><input type="text" name="file_mp4" /><br />',
         'Имя файла:<br/><input type="text" name="name" maxlength="64"/><br/>',
         'Описание файла:<br/><textarea name="about"></textarea><br/>';
    $sql = $db->prepare("SELECT * FROM category");
    while ($cat = $sql->fetch(PDO::FETCH_ASSOC)) echo '<input type="checkbox" name="option[]" value="'.$cat['id'].'"/> '.$cat['name'].'<br/>';
    echo '<input type="submit" name="submit" value="Отправить">',
         '</form>';
    
    echo '</div>';
     
    echo '<div class="content"><a href="'.ADMPANEL.'/">Назад в панель</a></div>';
    
    
} else {
    header('Location: /');
    exit;
}
$tpl->getFoot();