Print
Hits: 9837

This month Mozilla release new version of firefox - 3.6 - the best browser (for my opinion). I read that in this version it supported multiple files upload. So I add a patch for Joomla (1.5) to support it. This patch make the upload native php-html and non-flash involved in this patch. Also, this patch done with backward compatibility to older browser (even IE6).

 The first thing you should do is to update your component view. Just update the files administrator/components/com_media/views/images/tmpl/default.php and administrator/components/com_media/views/media/tmpl/default.php to support this patch (just add the bold brackets or replace the line):

<!--old version: <input type="file" id="file-upload" name="Filedata" multiple="multiple" />-->

<input type="file" id="file-upload" name="Filedata[]" multiple="multiple">

That's all for the view. Let's get to the business and update the php core that upload the files. Technically, all you've got to do is to update the file administrator/components/com_media/controllers/file.php. Replace the function upload() with the next function (in bold the updates from the original version):

/**
* Upload a file
* patched by oc666
* @since 1.5
*/
function upload()
{
global $mainframe;

// Check for request forgeries
JRequest::checkToken( 'request' ) or jexit( 'Invalid Token' );

$files = JRequest::getVar( 'Filedata', '', 'files', 'array' );
$folder        = JRequest::getVar( 'folder', '', '', 'path' );
$format        = JRequest::getVar( 'format', 'html', '', 'cmd');
$return        = JRequest::getVar( 'return-url', null, 'post', 'base64' );
$err        = null;

// Set FTP credentials, if given
jimport('joomla.client.helper');
JClientHelper::setCredentialsFromRequest('ftp');
$success_uploads = 0;
for($i=0;$i<count($files['name']);$i++) {
$file = array();
$file['name'] = $files['name'][$i];
$file['tmp_name'] = $files['tmp_name'][$i];

// Make the filename safe
jimport('joomla.filesystem.file');
$file['name']    = JFile::makeSafe($file['name']);
if (isset($file['name'])) {
$filepath = JPath::clean(COM_MEDIA_BASE.DS.$folder.DS.strtolower($file['name']));

if (!MediaHelper::canUpload( $file, $err )) {
if ($format == 'json') {
jimport('joomla.error.log');
$log = &JLog::getInstance('upload.error.php');
$log->addEntry(array('comment' => 'Invalid: '.$filepath.': '.$err));
//header('HTTP/1.0 415 Unsupported Media Type');
//jexit('Error. Unsupported Media Type!');

} /*else {
JError::raiseNotice(100, JText::_($err));
// REDIRECT
if ($return) {
$mainframe->redirect(base64_decode($return).'&folder='.$folder);
}
return;
}*/

}

if (JFile::exists($filepath)) {
if ($format == 'json') {
jimport('joomla.error.log');
$log = &JLog::getInstance('upload.error.php');
$log->addEntry(array('comment' => 'File already exists: '.$filepath));
//header('HTTP/1.0 409 Conflict');
//jexit('Error. File already exists');

}/* else {
JError::raiseNotice(100, JText::_('Error. File already exists'));
// REDIRECT
if ($return) {
$mainframe->redirect(base64_decode($return).'&folder='.$folder);
}
return;
}*/

}

if (!JFile::upload($file['tmp_name'], $filepath)) {
if ($format == 'json') {
jimport('joomla.error.log');
$log = &JLog::getInstance('upload.error.php');
$log->addEntry(array('comment' => 'Cannot upload: '.$filepath));
//header('HTTP/1.0 400 Bad Request');
//jexit('Error. Unable to upload file');

} else {/*
JError::raiseWarning(100, JText::_('Error. Unable to upload file'));
// REDIRECT
if ($return) {
$mainframe->redirect(base64_decode($return).'&folder='.$folder);
}
return;    */

$success_uploads++;
}
} else {
if ($format == 'json') {
jimport('joomla.error.log');
$log = &JLog::getInstance();
$log->addEntry(array('comment' => $folder));
//jexit('Upload complete');
} else {/*
$mainframe->enqueueMessage(JText::_('Upload complete'));
// REDIRECT
if ($return) {
$mainframe->redirect(base64_decode($return).'&folder='.$folder);
}
return;*/

$success_uploads++;
}
}
}/* else {
$mainframe->redirect('index.php', 'Invalid Request', 'error');
}*/

}
$mainframe->enqueueMessage(JText::sprintf('Uploads complete', $success_uploads));
if ($return) {
$mainframe->redirect(base64_decode($return).'&folder='.$folder);
}

}

Now we finish our patch. Just we add langauge patch for the string of the new upload. Add the next entry to your language file (this for en-GB):

// administrator/language/en-GB/en-GB.com_media.ini

... some other strings

UPLOADS COMPLETE=Upload Complete. Number of files uploaded: %s

That's all folks. If you've any improves, suggestions or errors, contact me or add comments to this post

Leave your comments

0
  • No comments found
Powered by Komento