Here is all the code I have for it ... I kinda abandoned that site.
upload.php
<?php
/** require core files **/
if(!defined('CORE')) require_once('core.php');
set_time_limit(86400); // 1 day
$Smarty->assign('uniqueID', uniqid());
/** setup max_file_size based on user access **/
if(isset($_SESSION['userid']) && (int)$_SESSION['userid'] !== 0){
/** member **/
$max_file_size = 1024000000;// 1GB : 1000 * 1024 * 1000
$Smarty->assign('max_file_size', $max_file_size);
$isGuest = FALSE;
} else {
/** guest **/
$max_file_size = 5120000;// 5MB : 3 * 1024 * 100
$Smarty->assign('max_file_size', $max_file_size);
$isGuest = TRUE;
}
/** setup and clear out previousCurrent **/
if(!isset($_SESSION['previousCurrent'])) $_SESSION['previousCurrent'] = 0;
if(isset($_GET['progress_key'])) {
apc_store('previousCurrent', $_SESSION['previousCurrent']);
$status = apc_fetch('upload_'.$_GET['progress_key']);
$currentRate = $status['current'] - $_SESSION['previousCurrent'];
$_SESSION['previousCurrent'] = $status['current'];
$status['rate'] = $currentRate;
$status['rateKbps'] = $currentRate/1024;
echo json_encode($status);
exit;
} elseif($_SERVER['REQUEST_METHOD'] == 'POST'){
$status = apc_fetch('upload_'.$_POST['APC_UPLOAD_PROGRESS']);
$status['done']=1;
echo json_encode($status);
if($isGuest){
$Smarty->assign('userID', 0);
} else {
$Smarty->assign('userID', $_SESSION['userid']);
}
require_once(LIB_DIR . DS . 'Spechal' . DS . 'SC_Upload.php');
$file = new SC_Upload();
$file->setFile($_FILES['upload1']);
if(empty($_POST['fileTitle'])) $_POST['fileTitle'] = '##::!::##';
if(empty($_POST['fileDescription'])) $_POST['fileDescription'] = '##::!::##';
$fileTitle = $DB->quoteSmart(strip_tags($_POST['fileTitle']));
$fileDescription = $DB->quoteSmart(strip_tags($_POST['fileDescription']));
$remoteIP = (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
/** make sure file uploaded successfully and is under size limit **/
if($file->didUpload() && ($file->getSize() <= $max_file_size)){
/** figure out a name **/
if(isset($isGuest) && $isGuest !== TRUE){
$filename = $SC_Auth->getUserID().'---'.time().$file->getRealName();
#echo 'Public: '.$file->getRealName().'<br />';
#echo 'Private: '.$filename;
$uploadDir = PRIV_DIR;
} else {
srand(time(0));
$filename = substr(md5(time().$remoteIP), 0, 24).$file->getRealName();
#echo 'Public: '.$file->getRealName().'<br />';
#echo 'Private: '.$filename;
$uploadDir = PUB_DIR;
}
$file->setPrivateName($filename);
/** zip the file if needed -- also gets moved and tmp removed **/
if($file->needsZipped($file->ext)){
require_once(LIB_DIR . DS . 'phpMyAdmin' . DS . 'zip.lib.php');
$add_file = $file->getTmpName();
// form is posted, handle it
$zipfile = new zipfile();
$f_tmp = fopen($add_file , 'rb');
if($f_tmp){
$dump_buffer=fread($f_tmp, filesize($add_file));
$zipfile->addFile($dump_buffer, $file->getRealName());
fclose($f_tmp);
} else {
$Smarty->display('zipError.tpl');
}
$dump_buffer = $zipfile -> file();
// response zip archive to browser:
/*header("Content-Type: application/octet-stream; name=".$file->getPrivateName());
header('Content-length: ' . strlen($dump_buffer));
header("Content-Transfer-Encoding: binary");
header("Accept-Ranges: none");
header('Content-Disposition: attachment; filename="'.$file->getPrivateName().'"');
header('Pragma: public');
echo $dump_buffer;*/
$file->setPrivateName($file->getPrivateName().'.zip');
$file->setRealName($file->getRealName().'.zip');
// write the file to disk
$file_pointer = fopen($uploadDir . DS . $file->getPrivateName(), 'w');
if($file_pointer){
fwrite($file_pointer, $dump_buffer, strlen($dump_buffer));
fclose($file_pointer);
}
$file->setValid(true);
/** delete tmp file **/
$file->deleteTmp();
} else {
$file->setValid(true);
/** move non-zipped file **/
if($file->moveUpload($uploadDir)){
/** delete tmp file **/
$file->deleteTmp();
} else {
/** error out cause file did not move from tmp dir **/
$Smarty->display('uploadErrorMove.tpl');
}
}
/** add record to DB **/
$ip = $remoteIP;
$time = date("YmdHis");
$pubName = $file->getRealName();
$privName = $file->getPrivateName();
$filesize = filesize($uploadDir . DS . $file->getPrivateName());
$mime = $file->getType();
$userID = (isset($_SESSION['userid'])) ? $_SESSION['userid'] : 0;
$private = ($userID > 0) ? 1 : 0;
$rating = 0;
$downloads = 0;
$lastdownload = $time;
$modified = $time;
$query = '';
$query = "INSERT INTO ".DB_PREFIX."files (id, localname, outputname, mimetype, filesize, filetitle, filedescription, added, modified, lastdownload, rating, downloads) ";
$query .= "VALUES ('', '".$privName."', '".$pubName."', '".$mime."', '".$filesize."', ".$fileTitle.", ".$fileDescription.", '".$time."', '".$modified."', '".$lastdownload."', '".$rating."', '".$downloads."')";
$DB->autoCommit(false);
if(!PEAR::isError(($ru = $DB->query($query)))){
/** add record to file map **/
$res = $DB->query("SELECT LAST_INSERT_ID()");
if(!PEAR::isError($res)){
$lid = $res->fetchInto($row, DB_FETCHMODE_ORDERED);
$lastInsert = $row[0];
$query = "INSERT INTO ".DB_PREFIX."filemap (uid, fid, private) VALUES ('".$userID."', '".$lastInsert."', '".$private."')";
if(!PEAR::isError(($ru = $DB->query($query)))){
/** add record to file archive **/
$query = "INSERT INTO ".DB_PREFIX."filearchive (id, fid, uid, filename, filetitle, filedescription, ip, timedate) ";
$query .= "VALUES ('', '".$lastInsert."', '".$userID."', '".$pubName."', ".$fileTitle.", ".$fileDescription.", '".$ip."', '".$time."')";
if(!PEAR::isError(($ru = $DB->query($query)))){
$DB->commit();
} else {
$DB->rollback();
$ERROR = true;
die($ru->getMessage());
}
} else {
$DB->rollback();
$ERROR = true;
die($ru->getMessage());
}
} else {
/** error out cause we could not get LAST_INSERT_ID() **/
$DB->rollback();
$ERROR = true;
die($res->getMessage());
}
} else {
/** error out cause file did add to DB **/
$DB->rollback();
$ERROR = true;
die($ru->getMessage());
}
} else {
/** file is over the limit or user is over the limit **/
$ERROR = true;
}
}
$query = "SELECT f.id, f.outputname, f.rating, f.downloads, f.added FROM ".DB_PREFIX."files AS f";
if(isset($_SESSION['userid'])) $query .= ", ".DB_PREFIX."filemap AS fm WHERE fm.fid=f.id AND fm.uid='".$_SESSION['userid']."'";
$query .= " ORDER BY f.added DESC LIMIT 200";
$ru = $DB->query($query);
if(!PEAR::isError($ru)){
$recentUploads = array();
while($ru->fetchInto($row, DB_FETCHMODE_ASSOC)){
$recentUploads[] = $row;
}
}
$Smarty->assign('recentUploads', $recentUploads);
if(!isset($_FILES['upload1']) && $_SERVER['REQUEST_METHOD'] !== 'POST'){
if($isGuest){
$Smarty->assign('userID', 0);
/** get guest files and pass them to Smarty **/
} else {
$Smarty->assign('userID', $_SESSION['userid']);
/** get users files and pass them to Smarty **/
}
/** show form **/
if(!isset($ERROR)) $Smarty->display('upload.tpl'); else $Smarty->display('uploadError.tpl');
}
$DB->disconnect();
?>