Beispiel #1
0
function batchupload($option)
{
    global $rsgConfig, $mainframe;
    $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::_(' is not a valid archive format. Only ZIP-files are 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_rsg2_images::batchupload_2($ziplist, $uploadfile->extractDir);
    } else {
        html_rsg2_images::batchupload($option);
    }
}
Beispiel #2
0
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;
        }
    }
}