[Openupload-svn-update] SF.net SVN: openupload:[141] trunk
Status: Beta
Brought to you by:
tsdogs
|
From: <ts...@us...> - 2008-11-12 18:56:35
|
Revision: 141
http://openupload.svn.sourceforge.net/openupload/?rev=141&view=rev
Author: tsdogs
Date: 2008-11-12 18:56:31 +0000 (Wed, 12 Nov 2008)
Log Message:
-----------
Add multiple file uploads at once
Modified Paths:
--------------
trunk/lib/main.inc.php
trunk/lib/modules/default/files.inc.php
trunk/plugins/mimetypes.inc.php
trunk/templates/default/modules/files/downloadConfirm.tpl
trunk/templates/default/modules/files/uploadForm.tpl
trunk/templates/default/modules/files/uploadOptions.tpl
trunk/www/setup.inc.php
Modified: trunk/lib/main.inc.php
===================================================================
--- trunk/lib/main.inc.php 2008-11-12 18:54:35 UTC (rev 140)
+++ trunk/lib/main.inc.php 2008-11-12 18:56:31 UTC (rev 141)
@@ -367,6 +367,13 @@
$this->tpl->assign('script',$_SERVER['PHP_SELF']);
$this->tpl->assign('page',$this->page);
+ if (isset($this->config['multiupload'])) {
+ if ($this->config['multiupload']<=0)
+ $this->config['multiupload']=1;
+ $this->tpl->assign('multiupload',$this->config['multiupload']);
+ } else {
+ $this->config['multiupload']=1;
+ }
/* check for banned IP */
if ($this->banned() != 'allow') {
$this->page['content'] = $this->fetch('banned');
Modified: trunk/lib/modules/default/files.inc.php
===================================================================
--- trunk/lib/modules/default/files.inc.php 2008-11-12 18:54:35 UTC (rev 140)
+++ trunk/lib/modules/default/files.inc.php 2008-11-12 18:56:31 UTC (rev 141)
@@ -62,7 +62,7 @@
global $_SESSION;
global $_FILES;
global $_SERVER;
-
+
if (isset($_FILES['upload'])) {
if ($_FILES['upload']['error']>0) {
switch ($_FILES['upload']['error']) { /* taken from here: http://it.php.net/manual/en/features.file-upload.errors.php */
@@ -78,28 +78,47 @@
}
$this->nextStep(1);
} else if ($_FILES['upload']['size']>app()->user->info('max_upload_size')) {
- app()->error(tr('Maximum file size exceeded!')); break;
+ app()->error(tr('Maximum file size exceeded!'));
+ break;
} else {
/* prepare the file */
$tmpname = app()->config['DATA_PATH'].'/tmp/'.randomName();
- move_uploaded_file($_FILES['upload']['tmp_name'],$tmpname);
- $_SESSION['user']['u']['tmp']=$tmpname;
- $_SESSION['user']['u']['mime']=$_FILES['upload']['type'];
- $_SESSION['user']['u']['name']=$_FILES['upload']['name'];
- $_SESSION['user']['u']['size']=$_FILES['upload']['size'];
- $_SESSION['user']['u']['ip']=$_SERVER['REMOTE_ADDR'];
- $_SESSION['user']['u']['user_login']=app()->user->info('login');
+ for ($i = 0; $i<app()->config['multiupload']; $i++) {
+ $u = 'upload';
+ $tmpnamex = $tmpname;
+ if ($i>0) {
+ $u = 'upload_'.$i;
+ $tmpnamex = $tmpname.'_'.$i;
+ }
+ if (isset($_FILES[$u]) and $_FILES[$u]['tmp_name']!='') {
+ move_uploaded_file($_FILES[$u]['tmp_name'],$tmpnamex);
+ $_SESSION['user']['u'][$i]['tmp']=$tmpnamex;
+ $_SESSION['user']['u'][$i]['mime']=$_FILES[$u]['type'];
+ $_SESSION['user']['u'][$i]['name']=$_FILES[$u]['name'];
+ $_SESSION['user']['u'][$i]['size']=$_FILES[$u]['size'];
+ $_SESSION['user']['u'][$i]['ip']=$_SERVER['REMOTE_ADDR'];
+ $_SESSION['user']['u'][$i]['user_login']=app()->user->info('login');
+ $result = app()->pluginAction('uploadComplete',$_SESSION['user']['u'][$i]);
+ if (!$result) { /* some plugin blocked the upload */
+ /* remove the file */
+ unset($_SESSION['user']['u']);
+ redirect();
+ }
+ }
+ }
$this->nextStep(app()->step);
}
- } else if (!isset($_SESSION['user']['u'])) {
+ } else if (!isset($_SESSION['user']['u'][0])) {
redirect();
}
- $result = app()->pluginAction('uploadOptions',$_SESSION['user']['u']);
+ $result = app()->pluginAction('uploadOptions',$_SESSION['user']['u'][0]);
if (!$result) { /* some plugin blocked the upload */
- /* remove the file */
+ /* remove the files */
+ unset($_SESSION['user']['u']);
redirect();
}
- $this->tpl->assign('finfo',$_SESSION['user']['u']);
+ $this->tpl->assign('finfo',$_SESSION['user']['u'][0]);
+ $this->tpl->assign('files',$_SESSION['user']['u']);
/* ask for information on the file */
}
@@ -112,37 +131,52 @@
/* display the information on the upload */
if (isset($_POST['description'])) {
/* move the file to the actual location */
- $finfo = $_SESSION['user']['u'];
- $finfo['description'] = $_POST['description'];
- /* now check plugins and if ok add file otherwise redirect */
- $result = app()->pluginAction('uploadConfirm',$finfo);
- if (!$result)
- $this->prevStep();
- /* everything ok then add the file */
- $finfo['id']= app()->db->newRandomId('files','id');
- $finfo['remove']= app()->db->newRandomId('files','remove');
- $finfo['upload_date'] = date('Y-m-d H:i:s');
- app()->db->insert('files',$finfo,array('id','name','mime','description','size','remove','user_login','ip','upload_date'));
- foreach (app()->plugins as $plugin) {
- if (count($plugin->fields)>0) {
- foreach ($plugin->fields as $f) {
- $pinfo['file_id'] = $finfo['id'];
- $pinfo['module'] = $plugin->name;
- $pinfo['name']=$f;
- $pinfo['value']=$finfo[$f];
- app()->db->insert('file_options',$pinfo,array('file_id','module','name','value'));
+ for ($i = 0; $i<count($_SESSION['user']['u']); $i++) {
+ $finfo = $_SESSION['user']['u'][$i];
+ $finfo['description'] = $_POST['description'];
+ /* now check plugins and if ok add file otherwise redirect */
+ if ($i==0) {
+ $result = app()->pluginAction('uploadConfirm',$finfo);
+ if (!$result)
+ $this->prevStep();
+ $finfo['id']= app()->db->newRandomId('files','id');
+ $mainid = $finfo['id'];
+ } else {
+ $finfo['id']=$mainid.'_'.$i;
+ }
+ /* everything ok then add the file */
+ $finfo['remove']= app()->db->newRandomId('files','remove');
+ $finfo['upload_date'] = date('Y-m-d H:i:s');
+ app()->db->insert('files',$finfo,array('id','name','mime','description','size','remove','user_login','ip','upload_date'));
+ if ($i==0) {
+ foreach (app()->plugins as $plugin) {
+ if (count($plugin->fields)>0) {
+ foreach ($plugin->fields as $f) {
+ $pinfo['file_id'] = $finfo['id'];
+ $pinfo['module'] = $plugin->name;
+ $pinfo['name']=$f;
+ $pinfo['value']=$finfo[$f];
+ app()->db->insert('file_options',$pinfo,array('file_id','module','name','value'));
+ }
+ }
}
+ } else {
+ $pinfo['file_id'] = $finfo['id'];
+ $pinfo['module'] = 'files';
+ $pinfo['name']='group';
+ $pinfo['value']=$mainid;
+ app()->db->insert('file_options',$pinfo,array('file_id','module','name','value'));
}
+ rename($_SESSION['user']['u'][$i]['tmp'],app()->config['DATA_PATH'].'/'.$finfo['id']);
+ $_SESSION['user']['u'][$i]=$finfo;
}
- rename($_SESSION['user']['u']['tmp'],app()->config['DATA_PATH'].'/'.$finfo['id']);
- $_SESSION['user']['u']=$finfo;
$this->nextStep();
}
}
function uploadFileInfo() {
- if (isset($_SESSION['user']['u']['id'])) {
- $finfo = $_SESSION['user']['u'];
+ if (isset($_SESSION['user']['u'][0]['id'])) {
+ $finfo = $_SESSION['user']['u'][0];
/* get the file info */
$finfo['downloadlink']= app()->config['WWW_SERVER'].app()->config['WWW_ROOT'].'/?action=d&id='.$finfo['id'];
$finfo['removelink']= app()->config['WWW_SERVER'].app()->config['WWW_ROOT'].'/?action=r&id='.$finfo['id'].'&removeid='.$finfo['remove'];
@@ -153,14 +187,21 @@
redirect();
}
}
-
+/**/
function loadFile($id) {
$finfo = app()->db->read('files',array('id'=>$id));
- $finfo = $finfo[0];
$pinfo = app()->db->read('file_options',array('file_id' => $id));
foreach ($pinfo as $v) {
- $finfo[$v['name']]=$v['value'];
+ $finfo[0][$v['name']]=$v['value'];
}
+ $afiles = app()->db->read('file_options',array('module' => 'files', 'name' => 'group', 'value' => $id));
+ if (count($afiles)>0) {
+ foreach ($afiles as $k => $a) {
+ $afile = app()->db->read('files',array('id'=>$a['file_id']));
+ $finfo[$k+1]=$afile[0];
+ }
+ }
+//print_r($finfo); exit();
return $finfo;
}
@@ -170,7 +211,7 @@
unset($_SESSION['user']['d']);
if (isset($_GET['id'])) {
- $_SESSION['user']['d']['id'] = $_GET['id'];
+ $_SESSION['user']['d'][0]['id'] = $_GET['id'];
$this->nextStep();
}
$finfo = array();
@@ -179,24 +220,26 @@
function downloadRequest() {
global $_GET;
+ global $_POST;
global $_SESSION;
-
+
$id = '';
if (isset($_POST['id'])) {
$id = $_POST['id'];
- } else if (isset($_SESSION['user']['d']['id'])) {
- $id = $_SESSION['user']['d']['id'];
+ } else if (isset($_SESSION['user']['d'][0]['id'])) {
+ $id = $_SESSION['user']['d'][0]['id'];
}
/* check if download exsists, and what are the properties */
if ($id != '') {
$finfo = $this->loadFile($id);
- if ($finfo['id']!=$id) {
+ if ($finfo[0]['id']!=$id) {
app()->error(tr('Requested file does not exsist!'));
$this->prevStep();
} else {
$_SESSION['user']['d']=$finfo;
- $this->tpl->assign('finfo',$finfo);
- $result = app()->pluginAction('downloadRequest',$finfo,false);
+ $this->tpl->assign('finfo',$finfo[0]);
+ $this->tpl->assign('files',$finfo);
+ $result = app()->pluginAction('downloadRequest',$finfo[0],false);
if ($result) {
$this->nextStep();
}
@@ -209,18 +252,20 @@
/* here we do the actual download of the file */
if (!isset($_SESSION['user']['d'])) {
redirect();
- } else if ($_SESSION['user']['d']['candownload']=='ok') {
+ } else if ($_SESSION['user']['d'][0]['candownload']=='ok') {
$finfo = $_SESSION['user']['d'];
- $this->tpl->assign('finfo',$finfo);
+ $this->tpl->assign('finfo',$finfo[0]);
+ $this->tpl->assign('files',$finfo);
/* download is allowed */
} else {
$finfo = $_SESSION['user']['d'];
/* check wether the plugins are ok */
- $result = app()->pluginAction('downloadConfirm',$finfo);
+ $result = app()->pluginAction('downloadConfirm',$finfo[0]);
if (!$result)
$this->prevStep();
+ for ($i = 0; $i<count($finfo); $i++)
+ $finfo[$i]['candownload']='ok';
$_SESSION['user']['d']=$finfo;
- $_SESSION['user']['d']['candownload']='ok';
/* now the user can download it */
$this->nextStep(app()->step);
}
@@ -229,21 +274,26 @@
function serveFile() {
global $_SESSION;
global $_POST;
+ global $_GET;
+ $num = 0;
+ if (isset($_GET['fid'])) {
+ $num = $_GET['fid'];
+ }
/* here we do the actual download of the file */
if (!isset($_SESSION['user']['d'])) {
redirect();
- } else if ($_SESSION['user']['d']['candownload']!='ok') {
+ } else if ($_SESSION['user']['d'][$num]['candownload']!='ok') {
$this->nextStep(2,'d');
} else {
$finfo = $_SESSION['user']['d'];
/* check wether the plugins are ok */
- $result = app()->pluginAction('serveFile',$finfo);
+ $result = app()->pluginAction('serveFile',$finfo[$num]);
if (!$result)
$this->nextStep(3,'d');
- $_SESSION['user']['d']['candownload']='ok';
+ $_SESSION['user']['d'][$num]['candownload']='ok';
/* if we got this far the download should begin serving */
- $file = app()->config['DATA_PATH'].'/'.$finfo['id'];
+ $file = app()->config['DATA_PATH'].'/'.$finfo[$num]['id'];
$filesize = filesize($file);
/* set to not timeout within default setting */
if (isset(app()->config['max_download_time'])) {
@@ -253,12 +303,12 @@
}
/* disable and clean output buffer so it won't reach memory limit */
ob_end_clean();
- header('Content-Type: '.$finfo['mime']);
+ header('Content-Type: '.$finfo[$num]['mime']);
header('Content-Length: '.$filesize);
- header('Content-Disposition: attachment; filename="'.$finfo['name'].'"');
+ header('Content-Disposition: attachment; filename="'.$finfo[$num]['name'].'"');
readfile($file);
/* file should have been sent now let's reset the download info */
- $_SESSION['user']['d']['candownload']='ko';
+ $_SESSION['user']['d'][$num]['candownload']='ko';
exit(0);
}
}
Modified: trunk/plugins/mimetypes.inc.php
===================================================================
--- trunk/plugins/mimetypes.inc.php 2008-11-12 18:54:35 UTC (rev 140)
+++ trunk/plugins/mimetypes.inc.php 2008-11-12 18:56:31 UTC (rev 141)
@@ -41,7 +41,7 @@
return true;
}
- function uploadOptions(&$finfo,$acl) {
+ function uploadComplete(&$finfo,$acl) {
if ($acl!='enable') return true;
$group = $this->getGroup();
if (count($this->config['allowed'][$group])==0) {
Modified: trunk/templates/default/modules/files/downloadConfirm.tpl
===================================================================
--- trunk/templates/default/modules/files/downloadConfirm.tpl 2008-11-12 18:54:35 UTC (rev 140)
+++ trunk/templates/default/modules/files/downloadConfirm.tpl 2008-11-12 18:56:31 UTC (rev 141)
@@ -1,14 +1,14 @@
{tr}You can now proceed downloading the file{/tr}:
<table border="0">
<tr><td>{tr}File description{/tr}:</td><td><b>{$finfo.description}</b></td></tr>
-<tr><td>{tr}File name{/tr}:</td><td><b>{$finfo.name}</b></td></tr>
-<tr><td>{tr}File size{/tr}:</td><td><b>{$finfo.size|fsize_format}</b></td></tr>
<tr><td>{tr}Uploaded on{/tr}:</td><td><b>{$finfo.upload_date}</b></td></tr>
{$plugins}
+{foreach from=$files item=f key=k}
+<tr><td>{tr}File name{/tr}:</td><td><b>{$f.name}</b></td></tr>
+<tr><td>{tr}File size{/tr}:</td><td><b>{$f.size|fsize_format}</b></td></tr>
+<td colspan="2" align="center"><a href="{$script}?action=g&fid={$k}">
+ <img src="{tpl file=/img/download.png}" border="0"><br>
+ {tr}Download file{/tr}</a></td></tr>
+{/foreach}
</table>
-<div id="downloadbutton"><br><center>
- <a href="{$script}?action=g">
- <img src="{tpl file=/img/download.png}" border="0"><br>
- {tr}Download file{/tr}</a></center>
-</div>
Modified: trunk/templates/default/modules/files/uploadForm.tpl
===================================================================
--- trunk/templates/default/modules/files/uploadForm.tpl 2008-11-12 18:54:35 UTC (rev 140)
+++ trunk/templates/default/modules/files/uploadForm.tpl 2008-11-12 18:56:31 UTC (rev 141)
@@ -1,8 +1,12 @@
{literal}
<script>
-function unhide() {
- $obj = document.getElementById('uploadbutton');
- $obj.style.visibility = 'visible';
+function unhide(i) {
+ obj = document.getElementById('uploadbutton');
+ obj.style.visibility = 'visible';
+
+ obj = document.getElementById('upload_'+i);
+ if (obj)
+ obj.style.visibility = 'visible';
}
</script>
{/literal}
@@ -14,8 +18,18 @@
<input type="hidden" name="MAX_FILE_SIZE" value="{$user.max_upload_size}">
{/if}
{tr}Select the file to be uploaded{/tr}<br>
- <input type="file" class="file" size="60" name="upload" onchange="if (this.value!='') unhide();"><br>
+ <input type="file" class="file" size="60" name="upload" onchange="if (this.value!='') unhide(1);"><br>
+{if isset($multiupload)}
+{section name=i start=1 loop=$multiupload}
{if isset($user.max_upload_size)}
+<div id="upload_{$smarty.section.i.index}" style="visibility: hidden">
+<input type="hidden" name="MAX_FILE_SIZE" value="{$user.max_upload_size}">
+{/if}
+<input type="file" class="file" size="60" name="upload_{$smarty.section.i.index}" onchange="if (this.value!='') unhide({$smarty.section.i.index+1});"><br>
+</div>
+{/section}
+{/if}
+{if isset($user.max_upload_size)}
<div id="msg">{tr}Maximum allowed upload size{/tr}: {$user.max_upload_size|fsize_format:"MB":0}</div>
{/if}
{$plugins}
Modified: trunk/templates/default/modules/files/uploadOptions.tpl
===================================================================
--- trunk/templates/default/modules/files/uploadOptions.tpl 2008-11-12 18:54:35 UTC (rev 140)
+++ trunk/templates/default/modules/files/uploadOptions.tpl 2008-11-12 18:56:31 UTC (rev 141)
@@ -3,8 +3,10 @@
<input type="hidden" name="action" value="{$action}">
<input type="hidden" name="step" value="{$nextstep}">
<table border="0">
-<tr><td>{tr}File name{/tr}:</td><td>{$finfo.name}</td></tr>
-<tr><td>{tr}File size{/tr}:</td><td>{$finfo.size|fsize_format}</td></tr>
+{foreach from=$files item=f}
+<tr><td>{tr}File name{/tr}:</td><td>{$f.name}</td></tr>
+<tr><td>{tr}File size{/tr}:</td><td>{$f.size|fsize_format}</td></tr>
+{/foreach}
<tr><td>{tr}Description{/tr}:</td><td><input id="description" type="text" size="30" name="description" value="{$finfo.description}"></td></tr>
{$plugins}
<tr><td colspan="2" align="right"><input class="submit" type="submit" value="{tr}Complete upload{/tr}"></td></tr>
Modified: trunk/www/setup.inc.php
===================================================================
--- trunk/www/setup.inc.php 2008-11-12 18:54:35 UTC (rev 140)
+++ trunk/www/setup.inc.php 2008-11-12 18:56:31 UTC (rev 141)
@@ -205,7 +205,7 @@
'dropdb' => 'DROP DATABASE "%1"',
'createdb' => 'CREATE DATABASE "%1"',
'dropuser' => '',
- 'createuser' => 'GRANT ALL PRIVILEGES TO "%1"@"localhost" ON %2.* IDENTIFIED BY "%3"',
+ 'createuser' => '',
'grant' => '',
'droptable' => 'DROP TABLE IF EXISTS `%2`',
);
@@ -448,10 +448,12 @@
unset($CONFIG['database']['name']);
} else {
unset($CONFIG['database']['rootdir']);
- $CONFIG['database']['host'] = 'localhost';
- $CONFIG['database']['user'] = '';
- $CONFIG['database']['password'] = '';
- $CONFIG['database']['name'] = 'openupload';
+ if (!isset($CONFIG['database']['host'])) {
+ $CONFIG['database']['host'] = 'localhost';
+ $CONFIG['database']['user'] = '';
+ $CONFIG['database']['password'] = '';
+ $CONFIG['database']['name'] = 'openupload';
+ }
}
return $step+1;
}
@@ -572,6 +574,7 @@
$CONFIG['registration']['email_confirm']=isset($_POST['confirmregistration'])?$_POST['confirmregistration']:'no';
$CONFIG['max_upload_size']=$_POST['max_upload_size'];
$CONFIG['max_download_time']=$_POST['max_download_time'];
+ $CONFIG['multiupload']=$_POST['max_download_time'];
if ($CONFIG['translator']=='') {
$error = true;
@@ -597,6 +600,10 @@
$error = true;
msg('Please insert a maximum download time','fail');
}
+ if ($CONFIG['multiupload']<1) {
+ $error = true;
+ msg('Please insert a max number of uploaded files per upload','fail');
+ }
if (!$error) {
return $step+1;
}
@@ -612,6 +619,7 @@
$CONFIG['registration']['email_confirm']='yes';
$CONFIG['max_upload_size']=100;
$CONFIG['max_download_time']=120;
+ $CONFIG['multiupload']=1;
}
?>
<form method="POST" action="index.php">
@@ -654,6 +662,7 @@
<tr><td>Template Footer:</td><td><textarea name="sitefooter" cols="50" rows="5"><?php echo $CONFIG['site']['footer']; ?></textarea></td></tr>
<tr><td>Maximum upload size (in MB):</td><td><input type="text" name="max_upload_size" value="<?php echo $CONFIG['max_upload_size']; ?>"></td></tr>
<tr><td>Maximum download time (in Min)<br>0 disables it:</td><td><input type="text" name="max_download_time" value="<?php echo $CONFIG['max_download_time']; ?>"></td></tr>
+<tr><td>Max num. of file uploaded per upload:</td><td><input type="text" name="multiupload" value="<?php echo $CONFIG['multiupload']; ?>"></td></tr>
<TR><TD colspan="2"><input type="submit" value="Next >>"></TD></TR>
</table>
</form>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|