Back to PhocaGalleryFileUpload class

Method realJavaUpload

public static
realJavaUpload
(mixed $frontEnd = 0)

Method realJavaUpload - Source code

public static function realJavaUpload($frontEnd = 0)
{
    $app = Factory::getApplication();
    Session::checkToken('request') or exit('ERROR: ' . Text::_('COM_PHOCAGALLERY_INVALID_TOKEN'));
    //	$files 	= JFactory::getApplication()->input->get( 'Filedata', '', 'files', 'array' );
    $path = PhocaGalleryPath::getPath();
    $folder = Factory::getApplication()->input->get('folder', '', '', 'path');
    if (isset($folder) && $folder != '') {
        $folder = $folder . '/';
    }
    $errUploadMsg = '';
    $ftp = ClientHelper::setCredentialsFromRequest('ftp');
    foreach ($_FILES as $fileValue => $file) {
        echo 'File key: ' . $fileValue . "\n";
        foreach ($file as $item => $val) {
            echo ' Data received: ' . $item . '=>' . $val . "\n";
        }
        // Make the filename safe
        if (isset($file['name'])) {
            $file['name'] = File::makeSafe($file['name']);
        }
        if (isset($file['name'])) {
            $filepath = Path::clean($path->image_abs . $folder . strtolower($file['name']));
            if (!PhocaGalleryFileUpload::canUpload($file, $errUploadMsg, $frontEnd)) {
                exit('ERROR: ' . Text::_($errUploadMsg));
            }
            if (File::exists($filepath)) {
                exit('ERROR: ' . Text::_('COM_PHOCAGALLERY_FILE_ALREADY_EXISTS'));
            }
            if (!File::upload($file['tmp_name'], $filepath, false, true)) {
                exit('ERROR: ' . Text::_('COM_PHOCAGALLERY_ERROR_UNABLE_TO_UPLOAD_FILE'));
            }
            if ((int) $frontEnd > 0) {
                return $file['name'];
            }
            exit('SUCCESS');
        } else {
            exit('ERROR: ' . Text::_('COM_PHOCAGALLERY_ERROR_UNABLE_TO_UPLOAD_FILE'));
        }
    }
    return true;
}