public function indx() { //Getting all post data if (Request::ajax()) { $data = Input::all(); $fileTblObj = new fileHandler(); $key = "uploaded_file"; if (Input::file($key)->isValid()) { $destinationPath = 'app/uploads/111/222/3'; // upload path $extension = Input::file($key)->getClientOriginalExtension(); // getting image extension $name = Input::file($key)->getClientOriginalName(); $curFilesize = Input::file($key)->getClientSize(); $mime = Input::file($key)->getMimeType(); // dd($mime); //$fileName = $name; // renameing image //$exstFileSize = Input::file($destinationPath, $fileName); if (!File::exists($destinationPath . "/boq-" . $name)) { //creating details for saving inthe file_handler Table $fileTblObj->user_id = $userid; $fileTblObj->eventName = $event; $fileTblObj->fileName = "boq-" . $name; $fileTblObj->formPage = 3; $fileTblObj->filePath = $destinationPath . "/"; $fileTblObj->mime = $mime; $ans->answer_text = 'Yes'; Input::file($key)->move($destinationPath, "boq-" . $name); // uploading file to given path //Input::file($key)->move($boqPath, $boqname); // uploading file to given path //Save filedetails $fileTblObj->save(); Session::flash('success', 'Upload successfully'); } else { if (File::size($destinationPath . "/" . $name) != $curFilesize) { $fileDtls = $fileTblObj->where('uid', $userid)->where('fileName', $name)->where('formPage', 3)->first(); Input::file($key)->move($destinationPath, $name); $ans->answer_text = 'Yes'; $ans->save(); $fileTblObj->where('id', $fileDtls->id)->update(array('updated_at' => date("Y-m-d h:m:s", time()))); } } //return Redirect::to('upload'); } die; } }
public function savepage6data() { $aa = Input::except(array('_token', 'back', 'save', 'next')); $afc = Input::file(); $count = 0; foreach ($aa as $key => $value) { $ids = explode("|", $key); //var_dump($ids); if (isset($ids[0]) && $ids[0] != "file") { if (isset($ids[1]) && $ids[1] != "") { $ans = Answer::find($ids[1]); $ans->answer_text = $value; $ans->save(); } else { $ans = new Answer(); $ans->question_id = $ids[0]; if (isset($ids[2]) && $ids[2] != "") { $ans->choice_id = $ids[2]; } $ans->user_id = Session::get('userid'); $ans->answer_text = $value; $ans->save(); } } } foreach ($afc as $key => $value) { $ids = explode("|", $key); if (isset($ids[0]) && $ids[0] == "file") { //If file Values are not printing then please check if // form has FIle=true //dd(Input::file($key)); $userid = Session::get('userid'); $event = Session::get('event'); $fileTblObj = new fileHandler(); $ans = Answer::find($ids[2]); if (isset($afc[$key])) { if (Input::file($key)->isValid()) { $count++; $destinationPath = 'app/uploads/' . $event . '/' . $userid . '/6'; // upload path $extension = Input::file($key)->getClientOriginalExtension(); // getting image extension $name = Input::file($key)->getClientOriginalName(); $curFilesize = Input::file($key)->getClientSize(); $mime = Input::file($key)->getMimeType(); // dd($mime); //$fileName = $name; // renameing image //$exstFileSize = Input::file($destinationPath, $fileName); if (!File::exists($destinationPath . "/" . $count . $name)) { //creating details for saving inthe file_handler Table $fileTblObj->user_id = $userid; $fileTblObj->eventName = $event; $fileTblObj->fileName = $count . $name; $fileTblObj->formPage = 6; $fileTblObj->filePath = $destinationPath . "/"; $fileTblObj->mime = $mime; $ans->answer_text = 'Yes'; $ans->save(); Input::file($key)->move($destinationPath, $count . $name); // uploading file to given path //Save filedetails $fileTblObj->save(); Session::flash('success', 'Upload successfully'); } else { if (File::size($destinationPath . "/" . $name) != $curFilesize) { $fileDtls = $fileTblObj->where('uid', $userid)->where('fileName', $name)->where('formPage', 6)->first(); Input::file($key)->move($destinationPath, $name); $ans->answer_text = 'Yes'; $ans->save(); $fileTblObj->where('id', $fileDtls->id)->update(array('updated_at' => date("Y-m-d h:m:s", time()))); } } //return Redirect::to('upload'); } } else { if ($ans->answer_text == '') { $ans->answer_text = 'No'; $ans->save(); } } } } }
/** * Copies all files from a folder to the /media folder. * It will NOT delete the media from the FTP-location * @param string Absolute path to the sourcefolder * @param string Absolute path to destination folder, defaults to Joomla /media folder */ function handleFTP($source, $destination = '') { global $ziplist, $mainframe; //Create unique install directory $tmpdir = uniqid('rsginstall_'); //Set destinatiopn if (!$destination) { $copyDir = JPath::clean(JPATH_ROOT . '/media/' . $tmpdir . '/'); } else { $copyDir = JPath::clean($destination . '/' . $tmpdir . '/'); } mkdir($copyDir); //Store dirname for cleanup at the end. $this->extractDir = $tmpdir; //Check for trailing slash in source path and add one if necessary $source = JPath::clean($source); //check source directory if (!file_exists($source) or !is_dir($source)) { echo $source . JText::_('_RSGALLERY_FU_FTP_DIR_NOT_EXIST'); $mainframe->redirect('index2.php?option=com_rsgallery2&task=batchupload', $source . JText::_('_RSGALLERY_FU_FTP_DIR_NOT_EXIST')); } //Read files from FTP-directory $files = JFolder::files($source, ''); if (!$files) { $mainframe->redirect('index2.php?option=com_rsgallery2&task=batchupload', JText::_('No valid images found in ') . $source . JText::_('. Please check the path.')); } //Create imagelist from FTP-directory foreach ($files as $file) { if (is_dir($source . $file)) { continue; } else { if (!in_array(fileHandler::getImageType($source . $file), $this->allowedFiles)) { continue; } else { //Add filename to list and copy to "/media/rsginstall_subdir" $list[] = $file; copy($source . $file, $copyDir . $file); } } } if (count($list) == 0) { echo JText::_('No files found to process!'); } else { return $list; } }
function save_batchupload() { global $rsgConfig, $mainframe; $database = JFactory::getDBO(); //Try to bypass max_execution_time as set in php.ini set_time_limit(0); $FTP_path = $rsgConfig->get('ftp_path'); $teller = rsgInstance::getInt('teller', null); $delete = rsgInstance::getVar('delete', null); $filename = rsgInstance::getVar('filename', null); $ptitle = rsgInstance::getVar('ptitle', null); $descr = rsgInstance::getVar('descr', array(0)); $extractdir = rsgInstance::getVar('extractdir', null); //Check if all categories are chosen if (isset($_REQUEST['category'])) { $category = rsgInstance::getVar('category', array(0)); } else { $category = array(0); } if (in_array('0', $category) || in_array('-1', $category)) { $mainframe->redirect("index2.php?option=com_rsgallery2&task=batchupload", JText::_('_RSGALLERY_ALERT_NOCATSELECTED')); } for ($i = 0; $i < $teller; $i++) { //If image is marked for deletion, delete and continue with next iteration if (isset($delete[$i]) and $delete[$i] == 'true') { //Delete file from server unlink(JPATH_ROOT . "/media/" . $extractdir . '/' . $filename[$i]); continue; } else { //Setting variables for importImage() $imgTmpName = JPATH_ROOT . "/media/" . $extractdir . '/' . $filename[$i]; $imgName = $filename[$i]; $imgCat = $category[$i]; $imgTitle = $ptitle[$i]; $imgDesc = $descr[$i]; //Import image $e = imgUtils::importImage($imgTmpName, $imgName, $imgCat, $imgTitle, $imgDesc); //Check for errors if ($e !== true) { $errors[] = $e; } } } //Clean up mediadir fileHandler::cleanMediaDir($extractdir); // Error handling if (isset($errors)) { if (count($errors) == 0) { echo JText::_('Item uploaded succesfully!'); } else { foreach ($errors as $err) { echo $err->toString(); } } } else { //Everything went smoothly, back to Control Panel global $mainframe; $mainframe->redirect("index2.php?option=com_rsgallery2", JText::_('Item uploaded succesfully!')); } }
function batchupload_2($ziplist, $extractDir) { /* Info for javascript on input element names and values: Step 2 Button: Upload --> task=save_batchupload Delete checkbox name: delete[1] Item title field name: ptitle[] Gallery select name: category[] Description area name: descr[] */ global $rsgOption; JHTML::_('behavior.mootools'); $database = JFactory::getDBO(); //Get variables from form $selcat = rsgInstance::getInt('selcat', null); $ftppath = rsgInstance::getVar('ftppath', null); $xcat = rsgInstance::getInt('xcat', null); $batchmethod = rsgInstance::getVar('batchmethod', null); ?> <script language="javascript" type="text/javascript"> <!-- function submitbutton(pressbutton) { var form = document.adminForm, missingCat = false, categories = $$('#adminForm input[name^=category]', '#adminForm select[name^=category]'); for (i=0 ; i<categories.length ; i++) { if (categories[i].value <= 0) { alert("<?php echo JText::_('All images must be part of a galery'); ?> "+' (#'+i+')'); return; missingCat = true; break; } } if (pressbutton == 'save_batchupload'){ if (missingCat == true) { alert("<?php echo JText::_('All images must be part of a galery'); ?> "); } else { form.submit(); } } } //--> </script> <form action="index2.php" method="post" name="adminForm" id="adminForm"> <table class="adminform"> <tr> <th colspan="5" class="sectionname"><font size="4"><?php echo JText::_('Step 2'); ?> </font></th> </tr> <tr> <?php // Initialize k (the column reference) to zero. $k = 0; $i = 0; foreach ($ziplist as $filename) { $k++; //Check if filename is dir if (is_dir(JPATH_ROOT . '/media/' . $extractDir . '/' . $filename)) { continue; } else { //Check if file is allowed $allowed_ext = array('gif', 'jpg', 'png'); $allowedVideo_ext = array('flv', 'avi', 'mov'); $ext = fileHandler::getImageType(JPATH_ROOT . '/media/' . $extractDir . '/' . $filename); if (in_array($ext, $allowedVideo_ext)) { // build preview image $basePath = JPATH_SITE . '/media/' . $extractDir . '/'; require_once JPATH_RSGALLERY2_ADMIN . 'includes/video.utils.php'; Ffmpeg::capturePreviewImage($basePath . $filename, $basePath . $filename . '.png'); $displayImage = $filename . '.png'; $i++; } else { if (!in_array($ext, $allowed_ext)) { continue; } else { $displayImage = $filename; $i++; } } } ?> <td align="center" valign="top" bgcolor="#CCCCCC"> <table class="adminform" border="0" cellspacing="1" cellpadding="1"> <tr> <th colspan="2"> </th> </tr> <tr> <td colspan="2" align="right"><?php echo JText::_('Delete'); ?> #<?php echo $i - 1; ?> : <input type="checkbox" name="delete[<?php echo $i - 1; ?> ]" value="true" /></td> </tr> <tr> <td align="center" colspan="2"><img src="<?php echo JURI_SITE . "/media/" . $extractDir . "/" . $displayImage; ?> " alt="" border="1" width="100" align="center" /></td> </tr> <input type="hidden" value="<?php echo $filename; ?> " name="filename[]" /> <tr> <td><?php echo JText::_('Title'); ?> </td> <td> <input type="text" name="ptitle[]" size="15" /> </td> </tr> <tr> <td><?php echo JText::_('Gallery'); ?> </td> <td><?php if ($selcat == 1 && $xcat !== '0') { ?> <input type="text" name="cat_text" value="<?php echo htmlspecialchars(stripslashes(galleryUtils::getCatnameFromId($xcat))); ?> " readonly /> <input type="hidden" name="category[]" value="<?php echo $xcat; ?> " /> <?php } else { echo galleryUtils::galleriesSelectList(null, 'category[]', false); } ?> </td> </tr> <tr> <td><?php echo JText::_('Description'); ?> </td> <td><textarea cols="15" rows="2" name="descr[]"></textarea></td> </tr> </table> </td> <?php if ($k == 5) { echo "</tr><tr>"; $k = 0; } } ?> </table> <input type="hidden" name="teller" value="<?php echo $i; ?> " /> <input type="hidden" name="extractdir" value="<?php echo $extractDir; ?> " /> <input type="hidden" name="option" value="com_rsgallery2" /> <input type="hidden" name="rsgOption" value="<?php echo $rsgOption; ?> " /> <input type="hidden" name="task" value="save_batchupload" /> </form> <?php }
function saveUploadedItem() { global $rsgConfig, $rsgAccess, $mainframe; $database = JFactory::getDBO(); //Set redirect URL $redirect = JRoute::_("index.php?option=com_rsgallery2&rsgOption=myGalleries", false); //Get category ID to check rights $i_cat = rsgInstance::getVar('i_cat', ''); //Get maximum number of images to upload $max_images = $rsgConfig->get('uu_maxImages'); //Check if user can upload in this gallery if (!$rsgAccess->checkGallery('up_mod_img', $i_cat)) { die('Unauthorized upload attempt!'); } //Check if number of images is not exceeded $count = 0; if ($count > $max_images) { //Notify user and redirect } else { //Go ahead and upload $upload = new fileHandler(); //Get parameters from form $i_file = rsgInstance::getVar('i_file', null, 'files', 'array'); $i_cat = rsgInstance::getInt('i_cat', ''); $title = rsgInstance::getVar('title', ''); $descr = rsgInstance::getVar('descr', '', 'post', 'string', JREQUEST_ALLOWRAW); $uploader = rsgInstance::getVar('uploader', ''); //Get filetype $file_ext = $upload->checkFileType($i_file['name']); //Check whether directories are there and writable $check = $upload->preHandlerCheck(); if ($check !== true) { $mainframe->redirect($redirect, $check); } switch ($file_ext) { case 'zip': if ($upload->checkSize($i_file) == 1) { $ziplist = $upload->handleZIP($i_file); //Set extract dir for uninstall purposes $extractdir = JPATH_ROOT . "/media/" . $upload->extractDir . '/'; //Import images into right folder for ($i = 0; $i < sizeof($ziplist); $i++) { $import = imgUtils::importImage($extractdir . $ziplist[$i], $ziplist[$i], $i_cat); } //Clean mediadir fileHandler::cleanMediaDir($upload->extractDir); //Redirect $mainframe->redirect($redirect, JText::_('Item uploaded succesfully!')); } else { //Error message $mainframe->redirect($redirect, JText::_('ZIP-file is too big!')); } break; case 'image': //Check if image is too big if ($i_file['error'] == 1) { $mainframe->redirect($redirect, JText::_('Image size is too big for upload')); } $file_name = $i_file['name']; if (move_uploaded_file($i_file['tmp_name'], JPATH_ROOT . "/media/" . $file_name)) { //Import into database and copy to the right places $imported = imgUtils::importImage(JPATH_ROOT . "/media/" . $file_name, $file_name, $i_cat, $title, $descr); if ($imported == 1) { if (file_exists(JPATH_ROOT . "/media/" . $file_name)) { unlink(JPATH_ROOT . "/media/" . $file_name); } } else { $mainframe->redirect($redirect, 'Importing image failed! Notify RSGallery2. This should never happen!'); } $mainframe->redirect($redirect, JText::_('Item uploaded succesfully!')); } else { $mainframe->redirect($redirect, JText::_('UPLOAD FAILED BACK TO UPLOADSCREEN')); } break; case 'error': $mainframe->redirect($redirect, JText::_('WRONG IMAGE FORMAT. WE WILL REDIRECT YOU TO THE UPLOAD SCREEN')); break; } } }
/** * This function is called when you select batchupload from the backend. It * detects whether you choose ZIP or FTP and acts accordingly. * When you choose ZIP it unzips the file you upload to "/media" for further * handling, if you choose FTP it reads the files from the directory you uploaded * the files to and copies them to "/media".(this dir must be on the local server). * @todo Better error trapping * @todo Check FTP handling bit */ function batch_uploadX($option) { global $mainframe, $rsgConfig; $database = JFactory::getDBO(); $FTP_path = $rsgConfig->get('ftp_path'); //Retrieve data from submit form $batchmethod = rsgInstance::getVar('batchmethod', null); $uploaded = rsgInstance::getVar('uploaded', null); $selcat = rsgInstance::getInt('selcat', null); $zip_file = rsgInstance::getVar('zip_file', null, 'FILES'); $ftppath = rsgInstance::getVar('ftppath', null); $xcat = rsgInstance::getInt('xcat', null); //Check if a gallery exists, if not link to gallery creation $database->setQuery("SELECT id FROM #__rsgallery2_galleries"); $database->query(); if ($database->getNumRows() == 0) { HTML_RSGALLERY::requestCatCreation(); return; } //New instance of fileHandler $uploadfile = new fileHandler(); if (isset($uploaded)) { if ($batchmethod == "zip") { //Check if file is really a ZIP-file if (!eregi('.zip$', $zip_file['name'])) { $mainframe->redirect("index2.php?option=com_rsgallery2&task=batchupload", $zip_file['name'] . ' ' . JText::_('NO_VALID_ARCHIVE_ONLY_ZIP_ALLOWED')); } else { //Valid ZIP-file, continue if ($uploadfile->checkSize($zip_file) == 1) { $ziplist = $uploadfile->handleZIP($zip_file); } else { //Error message $mainframe->redirect("index2.php?option=com_rsgallery2&task=batchupload", JText::_('ZIP-file is too big!')); } } } else { $ziplist = $uploadfile->handleFTP($ftppath); } HTML_RSGALLERY::batch_upload_2($ziplist, $uploadfile->extractDir); } else { HTML_RSGALLERY::batch_upload($option); } }