public function remoteuploadAction() { // header------------------------------------------------ $this->layout('layout/bags'); $catalog = $this->forward()->dispatch('Catalog\\Controller\\Index', array('action' => 'getdata')); $this->layout()->catalog = $catalog; $getuser = $this->forward()->dispatch('Admin\\Controller\\Index', array('action' => 'getuser')); // var_dump($getuser); $this->layout()->getuser = $getuser; // var_dump($getuser); $checklogin = $this->forward()->dispatch('Admin\\Controller\\Index', array('action' => 'session')); if ($checklogin) { if ($getuser->group == 'admin' || $getuser->group == 'supperadmin') { $arr = $this->forward()->dispatch('Catalog\\Controller\\Index', array('action' => 'getdata')); // var_dump($arr); $form = new RemoteForm('remoteform'); $form->addElements($arr); $tempFile = null; // -------------------------------upload mediafire server $getuser = $this->checkuserfolder($getuser); // -----------------------end mediafire upload------------------- $prg = $this->fileprg($form); if ($prg instanceof \Zend\Http\PhpEnvironment\Response) { return $prg; // Return PRG redirect response } elseif (is_array($prg)) { if ($form->isValid()) { $data = $form->getData(); $file_remote = $data['urlremote']; $file_headers = @get_headers($file_remote); if ($file_headers[0] == 'HTTP/1.1 404 Not Found') { $view = new ViewModel(); $exists = false; $view->exists = $exists; $view->setVariable('remoteform', $form); return $view; } else { $exists = true; $title = sprintf("%.0f ", microtime(true) * 20000); $title = str_replace(' ', '', $title); $name = md5(date('ymd')); if (!file_exists('temp/data/tmpuploads/videos/' . $name)) { mkdir('temp/data/tmpuploads/videos/' . $name, 0777, true); } $path2 = '/temp/data/tmpuploads/videos/' . $name; $path = ROOT_PATH . $path2; /* * $handle=file_get_contents($file); $fp = fopen($path.'/'.$title.'.mp4', "w"); fclose($fp); file_put_contents($path.'/'.$title.'.mp4', $handle); */ $fp = fopen($path . '/' . $title . '.mp4', "w"); $ch = curl_init(); $agent = $_SERVER['HTTP_USER_AGENT']; // echo $agent; curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE); curl_setopt($ch, CURLOPT_USERAGENT, $agent); curl_setopt($ch, CURLOPT_HTTPGET, TRUE); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $file_remote); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt($ch, CURLOPT_FILE, $fp); // curl_setopt($ch, CURLOPT_HEADER, 0); $k = curl_exec($ch); curl_close($ch); fclose($fp); var_dump($k); // die('stop'); // rename(ROOT_PATH.$path,ROOT_PATH.$path2.'/'.$title.'.'.$extension); $convert_link = ROOT_PATH . $path2 . '/' . $title . '.mp4'; // --------------------------- UPLOAD TO FTP SERVER------------------------------------------------------------------------------------------------------------- $convert_img = ROOT_PATH . $path2 . '/' . $title . '.jpg'; $convert_img_thumbnail = ROOT_PATH . $path2 . '/' . $title . '_thumbnail.jpg'; $convert_img_medium = ROOT_PATH . $path2 . '/' . $title . '_medium.jpg'; $medium = '500x280'; $thumbnail = '250x140'; ob_start(); passthru("ffmpeg -i {$convert_link} 2>&1"); $duration = ob_get_contents(); ob_end_clean(); $search = '/Duration: (.*?),/'; $duration = preg_match($search, $duration, $matches, PREG_OFFSET_CAPTURE, 3); $list_time = explode(':', $matches[1][0]); // var_dump($list_time); $video_time = 0; $sizearr = sizeof($list_time); for ($i = 0; $i < $sizearr; $i++) { echo (int) $list_time[$i]; echo "</br>"; echo pow(60, $sizearr - $i - 1); echo "</br>"; $video_time += (int) $list_time[$i] * pow(60, $sizearr - $i - 1); } // echo $video_time; $rand_time = rand(0, $video_time); // echo $rand_time; exec("ffmpeg -i {$convert_link} -deinterlace -an -ss {$rand_time} -f mjpeg -t 0.01 -r 1 -y {$convert_img} 2>&1 "); exec("ffmpeg -i {$convert_link} -deinterlace -an -ss {$rand_time} -f mjpeg -t 0.01 -r 1 -y -s {$thumbnail} {$convert_img_thumbnail} 2>&1 "); exec("ffmpeg -i {$convert_link} -deinterlace -an -ss {$rand_time} -f mjpeg -t 0.01 -r 1 -y -s {$medium} {$convert_img_medium} 2>&1 "); $path3 = substr($path2, 29); $local = $this->getLocalTable()->getserver(1); $blockCipher = BlockCipher::factory('mcrypt', array('algo' => 'aes')); $blockCipher->setKey('foxvsky'); $local->ftppass = $blockCipher->decrypt($local->ftppass); $dir = $local->path . '/data/upload/videos/' . $path3 . '/' . md5($title . 'foxvsky'); $file = ROOT_PATH . $path2 . '/' . $title . '.mp4'; $remote_file = $dir . '/' . md5($title . 'aihoa') . '.mp4'; $remote_img = $local->path . '/data/upload/images/' . $path3 . '/' . md5($title . 'mylove') . '/large.jpg'; $remote_thumbnail = $local->path . '/data/upload/images/' . $path3 . '/' . md5($title . 'mylove') . '/thumbnail.jpg'; $remote_medium = $local->path . '/data/upload/images/' . $path3 . '/' . md5($title . 'mylove') . '/medium.jpg'; $conn_id = ftp_connect($local->ip); $login_result = ftp_login($conn_id, $local->ftpusername, $local->ftppass); $this->ftp_mksubdirs($conn_id, $local->path, 'data/upload/videos/' . $path3 . '/' . md5($title . 'foxvsky')); $this->ftp_mksubdirs($conn_id, $local->path, 'data/upload/images/' . $path3 . '/' . md5($title . 'mylove')); $upload_vid = ftp_put($conn_id, $remote_file, $file, FTP_BINARY); $upload_img = ftp_put($conn_id, $remote_img, $convert_img, FTP_BINARY); $upload_img_thumbnail = ftp_put($conn_id, $remote_thumbnail, $convert_img_thumbnail, FTP_BINARY); $upload_img_medium = ftp_put($conn_id, $remote_medium, $convert_img_medium, FTP_BINARY); $video_link = $local->link . '/data/upload/videos/' . $path3 . '/' . md5($title . 'foxvsky') . '/' . md5($title . 'aihoa') . '.mp4'; $img_link = $local->link . '/data/upload/images/' . $path3 . '/' . md5($title . 'mylove') . '/large.jpg'; echo "<img src='http://" . $img_link . "'/></br>"; echo "<video src='http://" . $video_link . "'/></video></br>"; ftp_close($conn_id); // ------------------------------------------------END FTP UPLOAD-------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------UPLOAD MEDIAFIRE SERVER------------------------------------------------------------------------------------------------------------- $getuser = $this->checkuserfolder($getuser); $hash = hash_file('sha256', $convert_link); $size = filesize($convert_link); $files = array(); $files['filename'] = $title . '.mp4'; $files['hash'] = $hash; $files['size'] = $size; $files['url'] = 'http://' . $video_link; $files['folder_key'] = $getuser->folder_key; // var_dump($file); // echo "</br>"; $ex = $this->getExTable()->getserver($getuser->externalsv_id); $mediafire = new ConnectMS($ex); $add = $mediafire->add_web_upload($files); $quickkey = $mediafire->instant($files); if (!isset($quickkey) && !$quickey) { $quickkey = ''; $direct_link = ''; } else { $direct_link = $mediafire->get_link($quickkey); } $video = new Main(); $video->exchangeArray($form->getData()); $video->seriecode = $title; $video->duration = substr($matches[1][0], 0, 8); $video->folder_key = $getuser->folder_key; $video->quick_key = $quickkey; $video->local_link = 'http://' . $video_link; $video->imgfolder = 'http://' . $local->link . '/data/upload/images/' . $path3 . '/' . md5($title . 'mylove'); $video->localsv_id = $local->id; $video->externalsv_id = $getuser->externalsv_id; $video->external_link = $direct_link; // var_dump($video);die('123'); // ------------------------------------------------END MEDIAFIRE UPLOAD------------------------------------------------------------------------------------ $check = $this->getMainTable()->saveVideo($video); if (!$check) { return $this->redirect()->toUrl(WEBPATH . '/main/edit/' . $title, true); } else { $this->layout()->check = $check; } } } else { $fileErrors = $form->get('seriecode')->getMessages(); if (empty($fileErrors)) { $tempFile = $form->get('seriecode')->getValue(); } } } return array('remoteform' => $form, 'tempFile' => $tempFile); } else { return $this->layout('error/admin'); } } else { return $this->layout('error/admin'); } }
public function adicionartipousuarioAction() { $mainTable = 'tipos_usuarios'; // obtém a requisição $request = $this->getRequest(); // verifica se a requisição é do tipo post if ($request->isPost()) { // instancia formulário $form = new MainForm($mainTable); // instancia model curso com regras de filtros e validações $modelMain = new Main(); // passa para o objeto formulário as regras de viltros e validações // contidas na entity usuario $form->setInputFilter($modelMain->getInputFilter($mainTable)); // passa para o objeto formulário os dados vindos da submissão $form->setData($request->getPost()); // verifica se o formulário segue a validação proposta if ($form->isValid()) { // aqui vai a lógica para adicionar os dados à tabela no banco // 1 - popular model com valores do formulário $modelMain->exchangeArray($form->getData()); // 2 - persistir dados do model para banco de dados $this->getMainTable($mainTable)->save($modelMain, $mainTable); // redirecionar para action index no controller aluno return $this->redirect()->toRoute('main'); } else { // em caso da validação não seguir o que foi definido // renderiza para action novo com o objeto form populado, // com isso os erros serão tratados pelo helpers view return (new ViewModel())->setVariable('formTiposUsuarios', $form)->setTemplate('main/main/novotipousuario'); } } }