/** * Function for uploading of videos via the upload form * * @return void * @author Praveen Rajan */ function upload_videos() { // Videos must be an array $videoslist = array(); // get selected gallery $galleryID = (int) $_POST['galleryselect']; if ($galleryID == 0) { CvgCore::show_video_error(__('No gallery selected !')); return; } // get the path to the gallery $gallery = videoDB::find_gallery($galleryID); if (empty($gallery->path)) { CvgCore::show_video_error(__('Failure in database, no gallery path set !')); return; } // read list of images $dirlist = CvgCore::scandir_video_name($gallery->abspath); $videofiles = $_FILES['videofiles']; if (is_array($videofiles)) { foreach ($videofiles['name'] as $key => $value) { // look only for uploded files if ($videofiles['error'][$key] == 0) { $temp_file = $videofiles['tmp_name'][$key]; $temp_file_size = filesize($temp_file); $temp_file_size = intval(CvgCore::wp_convert_bytes_to_kb($temp_file_size)); $max_upload_size = CvgCore::get_max_size(); if ($temp_file_size > $max_upload_size) { CvgCore::show_video_error(__('File upload size limit exceeded.')); continue; } //clean filename and extract extension $filepart = CvgCore::fileinfo($videofiles['name'][$key]); $filename = $filepart['basename']; $file_name = $filepart['filename']; // check for allowed extension and if it's an image file $ext = array('mp4', 'flv', 'MP4', 'FLV', 'mov', 'MOV', 'mp3', 'MP3'); if (!in_array($filepart['extension'], $ext) || !@filesize($temp_file)) { CvgCore::show_video_error('<strong>' . $videofiles['name'][$key] . ' </strong>' . __('is no valid video file !')); continue; } // check if this filename already exist in the folder $i = 0; while (in_array($file_name, $dirlist)) { $i++; $filename = $filepart['filename'] . '_' . $i . '.' . $filepart['extension']; $file_name = $filepart['filename'] . '_' . $i; } $dest_file = $gallery->abspath . '/' . $filename; //check for folder permission if (!is_writeable($gallery->abspath)) { $message = sprintf(__('Unable to write to directory %s. Is this directory writable by the server?'), $gallery->abspath); CvgCore::show_video_error($message); return; } // save temp file to gallery if (!@move_uploaded_file($temp_file, $dest_file)) { CvgCore::show_video_error(__('Error, the file could not moved to : ') . $dest_file); continue; } if (!CvgCore::chmod($dest_file)) { CvgCore::show_video_error(__('Error, the file permissions could not set.')); continue; } // add to imagelist & dirlist $videolist[] = $filename; $dirlist[] = $file_name; } else { CvgCore::show_video_error(CvgCore::decode_upload_error($videofiles['error'][0])); return; } } } if (count($videolist) > 0) { // add videos to database $videos_ids = CvgCore::add_Videos($galleryID, $videolist); if (CvgCore::ffmpegcommandExists("ffmpeg")) { foreach ($videos_ids as $video_id) { CvgCore::create_thumbnail_video($video_id); } } CvgCore::show_video_message(count($videos_ids) . __(' Video(s) successfully added.')); } return; }