Code: Select all
<?php
class index extends front{
function public_main (){
$this->public_dir();
} // public_main
function public_dir() {
$this->Frame->Title('Main');
$dir = $this->getDir();
$this->Frame->assign('currentLoc', str_replace('%2F', '/', rawurlencode($dir)));
$this->Frame->assign('userinfo', $this->uinfo);
$list = $this->getDirList($dir);
if ($list !== false) {
$this->Frame->assign('dirs', $this->getDirs());
$this->Frame->assign('list', $list);
$this->Frame->display('main', true, true);
} // if
else {
$this->Frame->assign('err', 'Aplankas neegzistuoja.');
$this->Frame->display('error');
} // else
} // public_dir()
function public_file() {
$file = $this->getDir();
$fulldir = filedir . $this->uinfo['id'] . '/' . trim($file, '/');
$filename = file_iexists($fulldir);
if ($filename != false) {
$q = mysql_query("SELECT * FROM `files` WHERE CONCAT(`fulldir`, '/', `name`) = '" . mysql_real_escape_string($file) . "' OR (`fulldir` = '' AND `name` = '" . mysql_real_escape_string($file) . "') LIMIT 1");
if (mysql_num_rows($q) == 1) {
$q = mysql_fetch_assoc($q);
$userinfo = $this->Mysql->SelectSingle('user', null, array('userid' => $q['user_id']));
$fulldir = str_replace('//', '/', (filedir . $this->uinfo['id'] . '/' . $q['fulldir'] . '/' . $q['name']));
$size = round(filesize($fulldir) / 1024, 2);
$unit = 'kb';
if ($size > 1024) {
$size = round($size / 1024, 2);
$unit = 'mb';
} // if
$data = array(
'id' => $q['id'],
'name' => $q['name'],
'ext' => getExt($q['name']),
'fulldir' => $q['fulldir'],
'link' => basedir . '/index/down/' . $q['id'],
'user_id' => $q['user_id'],
'size' => $size,
'unit' => $unit,
'dlist' => unserialize(base64_decode($q['downby'])),
'downtimes' => $q['downtimes'],
'uploaded' => $q['uploaded'],
'username' => $userinfo['username']
);
$this->Frame->assign('data', $data)
$dirs = $this->getDirs();
$dirs = array_slice($dirs, 0, sizeof($dirs) - 1);
$this->Frame->assign('dirs', $dirs);
$this->Frame->display('file', true, true);
} // if
else {
$this->Frame->assign('err', 'Failas neegzistuoja.');
$this->Frame->display('error');
} // else
} // if
else {
$this->Frame->assign('err', 'Failas neegzistuoja.');
$this->Frame->display('error');
} // else
} // public_file
function public_fileinfo() {
if (isset($_GET['0']) && checkUuid($_GET['0'])) {
$q = $this->Mysql->SelectSingle('files', null, array('id' => $_GET['0']));
if (!empty($q)) {
$userinfo = $this->Mysql->SelectSingle('user', null, array('userid' => $q['user_id']));
$fulldir = str_replace('//', '/', (filedir . $q['user_id'] . '/' . $q['fulldir'] . '/' . $q['name']));
$size = round(filesize($fulldir) / 1024, 2);
$unit = 'kb';
if ($size > 1024) {
$size = round($size / 1024, 2);
$unit = 'mb';
} // if
$data = array(
'id' => $q['id'],
'name' => $q['name'],
'ext' => getExt($q['name']),
'fulldir' => $q['fulldir'],
'link' => basedir . '/index/down/' . $q['id'],
'user_id' => $q['user_id'],
'size' => $size,
'unit' => $unit,
'dlist' => unserialize(base64_decode($q['downby'])),
'downtimes' => $q['downtimes'],
'uploaded' => $q['uploaded'],
'username' => $userinfo['username']
);
$this->Frame->assign('data', $data);
$this->Frame->display('fileinfo', true, true);
} // if
else {
$this->Frame->assign('err', 'Failas neegzistuoja.');
$this->Frame->display('error');
} // else
} // if
else {
$this->Frame->assign('err', 'Failas neegzistuoja.');
$this->Frame->display('error');
} // else
} // public_file
function public_login() {
$this->Frame->Title('Prisijungimas');
if (isset($_POST['buttonlogin'])) {
if ($this->checkLoginPost() == true) {
$this->Frame->redirect(basedir);
die();
} // if
else {
$this->displayError('Bad username and/or password.');
}
} // if
$this->Frame->display('login');
} // public_login
function public_logout() {
$this->delLogin();
} // public_logout
function public_upload() {
if (!empty($_FILES['fileToUpload'])) {
$_FILES['fileToUpload']['name'] = $this->renameFile($_FILES['fileToUpload']['name']);
$dir = $this->getDir();
if ($this->checkUpload($_FILES['fileToUpload'])) {
if ($this->doFileUpload($_FILES['fileToUpload'], $dir)) {
if ($this->doDbUpload($_FILES['fileToUpload'], $dir)) {
echo $_FILES['fileToUpload']['name'];
} // if
// echo 'true';
else {
$this->doFileUnUpload($_FILES['fileToUpload'], $dir);
echo 'false';
} // else
} // if
else
echo 'false';
} // if
else
echo 'false';
} // if
else
echo 'false';
} // public_upload
function public_doupload() {
$i = $this->getUploadInfo();
if ($i == false)
return false;
else {
$userid = $i['userid'];
$dir = $i['dir'];
}
$uploadDir = filedir . $userid . '/' . $dir;
$_FILES['Filedata']['name'] = $this->renameFile($_FILES['Filedata']['name']);
$uploadFile = $uploadDir . '/' . basename($_FILES['Filedata']['name']);
if ($_POST['submit'] != '') {
// 1. submitting the html form
if (!in_array('jquploader', $_GET)) {
// 1.a javascript off, we need to upload the file
if (move_uploaded_file ($_FILES[0]['tmp_name'], $uploadFile)) {
chmod($uploadFile, 0777);
// delete the file
// @unlink ($uploadFile);
$html_body = '<h1>File successfully uploaded!</h1><pre>';
$html_body .= print_r($_FILES, true);
$html_body .= '</pre>';
} else {
$html_body = '<h1>File upload error!</h1>';
switch ($_FILES[0]['error']) {
case 1:
$html_body .= 'The file is bigger than this PHP installation allows';
break;
case 2:
$html_body .= 'The file is bigger than this form allows';
break;
case 3:
$html_body .= 'Only part of the file was uploaded';
break;
case 4:
$html_body .= 'No file was uploaded';
break;
default:
$html_body .= 'unknown errror';
}
$html_body .= 'File data received: <pre>';
$html_body .= print_r($_FILES, true);
$html_body .= '</pre>';
}
$html_body = '<h1>Full form</h1><pre>';
$html_body .= print_r($_POST, true);
$html_body .= '</pre>';
} else {
// 1.b javascript on, so the file has been uploaded and its filename is in the POST array
$html_body = '<h1>Form posted!</h1><p>Error:<pre>';
$html_body .= print_r($_POST, false);
$html_body .= '</pre>';
}
} else {
if (in_array('jquploader', $_GET)) {
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// 2. performing jqUploader flash upload
if ($_FILES['Filedata']['name']) {
if (move_uploaded_file ($_FILES['Filedata']['tmp_name'], $uploadFile)) {
chmod($uploadFile, 0777);
$file = array(
'name' => $this->renameFile($_FILES['Filedata']['name']),
'size' => $_FILES['Filedata']['size']
);
$this->doDbUploadUsr($file, $dir, $userid);
// delete the file
// @unlink ($uploadFile);
return $uploadFile;
}
} else {
if ($_FILES['Filedata']['error']) {
return $_FILES['Filedata']['error'];
}
}
}
}
} // public_doupload
function public_redirect() {
if ($_POST['filename'] != '') {
$location = $this->getDirUsr();
header('location: ' . basedir . '/index/file/' . $location . '/' . $this->renameFile($_POST['filename']));
die();
} // if
}
function public_newdir() {
$dir = $this->getDir();
$dir = strtolower($this->renameFile($dir));
if (mkdir(filedir . $this->uinfo['id'] . '/' . $dir, 0777)) {
echo 'true';
} // if
else
echo 'false';
} // public_newdir
function public_deletefile() {
$file = $this->getFileData();
if ($file != false) {
$f = filedir . $this->uinfo['id'] . '/' . $file['fulldir'] . '/' . $file['name'];
if (file_exists($f)) {
$size = round(filesize($f) / 1024 ,2);
if (unlink($f)) {
$this->Mysql->Delete('files', array('id' => $file['id']));
mysql_query("UPDATE `user` SET `size` = `size` - " . $size . " WHERE `userid` = " . $this->uinfo['id']);
echo 'true';
} // if
else
echo 'false';
} // else
else
echo 'false';
} // if
else
echo 'falses';
} // public_deletefile
function public_deletedir() {
$dir = $this->getDir();
$fulldir = filedir . $this->uinfo['id'] . '/' . trim($dir, '/');
if (is_dir($fulldir)) {
mysql_query("DELETE FROM `files` WHERE `fulldir` LIKE '" . $dir . "%' AND `user_id` = " . $this->uinfo['id']);
$this->removeDirRecurive($fulldir);
echo 'true';
} // if
else
echo 'false';
} // public_delete
function public_test() {
$this->Frame->assign('err', 'KLAIDA');
$this->Frame->display('ajax_error');
}
function public_player() {
$data = $this->getFileData();
$data['link'] = basedir . '/index/download/' . $data['id'];
$this->Frame->assign('data', $data);
$this->Frame->display('player');
} // public_player
function public_download() {
if (isset($_GET['0']) && checkUuid($_GET['0'])) {
$data = $this->Mysql->SelectSingle('files', null, array('id' => $_GET['0']));
if (!empty($data)) {
$location = basedir . str_replace('//', '/', filedirup . $data['user_id'] . '/' . $data['fulldir'] . '/' . $data['name']);
header("Content-Type: application/force-download");
header("Content-Type: application/download");
header("Content-Description: File Transfer");
header('location: ' . $location);
die();
} // if
else {
$this->Frame->assign('err', 'Failas neegzistuoja.');
$this->Frame->display('error');
} // else
} // if
else {
$this->Frame->assign('err', 'Failas neegzistuoja.');
$this->Frame->display('error');
} // else
} // download
function public_down() {
if (isset($_GET['0']) && checkUuid($_GET['0'])) {
$data = $this->Mysql->SelectSingle('files', null, array('id' => $_GET['0']));
if (!empty($data)) {
if (isset($this->uinfo['username'])) {
$arr = (array) unserialize(base64_decode($data['downby']));
if (!in_array($this->uinfo['username'], $arr)) {
$arr[] = $this->uinfo['username'];
$this->Mysql->Query("UPDATE `files` SET `downby` = '" . base64_encode(serialize($arr)) ."', `downtimes` = `downtimes` + 1, `lastdown` = '" . time() . "' WHERE `id` = '" . $data['id'] . "'");
} // if
} // if
$file_name = str_replace('//', '/', filedir . $data['user_id'] . '/' . $data['fulldir'] . '/' . $data['name']);
$location = basedir . str_replace('//', '/', filedirup . $data['user_id'] . '/' . $data['fulldir'] . '/' . $data['name']);
// required for IE
if(ini_get('zlib.output_compression')) { ini_set('zlib.output_compression', 'Off'); }
// get the file mime type using the file extension
switch(strtolower(substr(strrchr($file_name,'.'),1)))
{
case 'pdf': $mime = 'application/pdf'; break;
case 'zip': $mime = 'application/zip'; break;
case 'jpeg':
case 'jpg': $mime = 'image/jpg'; break;
default: $mime = 'application/force-download';
}
header('Pragma: public'); // required
header('Expires: 0'); // no cache
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Last-Modified: '.gmdate ('D, d M Y H:i:s', filemtime ($file_name)).' GMT');
header('Cache-Control: private',false);
header('Content-Type: Application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($file_name).'"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: '.filesize($file_name)); // provide file size
header('Connection: close');
readfile($file_name); // push it out
die();
} // if
else {
$this->Frame->assign('err', 'Failas neegzistuoja.');
$this->Frame->display('error');
} // else
} // if
else {
$this->Frame->assign('err', 'Failas neegzistuoja.');
$this->Frame->display('error');
} // else
} // download
function public_faq(){
$text = $this->Mysql->SelectSingle('mmup_faq');
$this->Frame->assign('text', $text);
$this->Frame->display('faq', true, true);
}
function public_news(){
$text = $this->Mysql->SelectSingle('mmup_news');
$this->Frame->assign('text', $text);
$this->Frame->display('news', true, true);
}
function displayNoThumb() {
$Image = $this->Frame->NewImage();
$img = $Image->createFromFile('./images/nothumb.gif', 'gif');
$Image->show_image($img, 'gif');
} // displayNoThumb
function getDirList($dir = '') {
function findId($path, $list)
{
foreach($list as $key => $val)
{
if ($val['dir'] == $path)
return $key;
} // foreach
return false;
} // findId
function doSort($a, $b) {
if ($a['uploaded'] == $b['uploaded']) {
return 0;
}
return ($a['uploaded'] < $b['uploaded']) ? -1 : 1;
} // doSort
function doSortF($a, $b) {
if ($a['name'] == $b['name']) {
return 0;
}
return ($a['name'] < $b['name']) ? -1 : 1;
} // doSort
$dir = trim($dir, '/');
$fulldir = filedir . '/' . $this->uinfo['id'] . '/' . $dir;
$fulldir = str_replace('//', '/', $fulldir);
if (is_dir($fulldir)) {
if ($dh = opendir($fulldir)) {
$list = $ids = $dirlist = array();
while (($file = readdir($dh)) !== false) {
if (($file != '.') && ($file != '..')) {
$size = round(filesize($fulldir . '/' . $file) / 1024, 2);
$unit = 'kb';
if ($size > 1024) {
$size = round($size / 1024, 2);
$unit = 'mb';
} // if
$type = filetype(trim($fulldir . '/' . $file));
$d = trim($dir . '/' . $file, '/');
if ($type != 'dir') {
$list[] = array(
'id' => '',
'name' => $file,
'type' => $type,
'ext' => getExt($file),
'size' => $size,
'unit' => $unit,
'dir' => $d,
'uploaded' => ''
);
$ids[] = "'" . $d . "'";
} // if
else {
$dirlist[] = array(
'id' => '',
'name' => $file,
'type' => $type,
'ext' => getExt($file),
'size' => $size,
'unit' => $unit,
'dir' => $d
);
}
} // if
} // while
if (!empty($ids)) {
$ids = $this->Mysql->Query("SELECT * FROM `files` WHERE CONCAT(`fulldir`, '/', `name`) IN (" . implode(', ', $ids) . ") OR (`fulldir` = '' && `name` IN(" . implode(', ', $ids) . "))");
$ids = $this->Mysql->FetchTable($ids);
foreach ($ids as $hand) {
if (($key = findId(trim($hand['fulldir'] . '/' . $hand['name'], '/'), $list)) !== false){
$list[$key]['id'] = $hand['id'];
$list[$key]['uploaded'] = $hand['uploaded'];
} // if
} // foreach
} // if
usort($list, "doSort");
usort($dirlist, "doSortF");
$list = array_merge($list, $dirlist);
return $list;
} // if
else
return false;
} // if
else {
if ($dir == '') {
if (mkdir(filedir . $this->uinfo['id']))
return array();
else
return false;
} // if
else
return false;
} // else
} // getDirList
function getDir() {
$list = $_GET;
unset($list['exec'], $list['run']);
$dir = implode('/', $list);
return trim($dir, '/');
} // getDir
function getDirUsr() {
$list = $_GET;
unset($list['exec'], $list['run'], $list['0']);
$dir = implode('/', $list);
return trim($dir, '/');
} // getDir
function getUploadInfo() {
$list = $_GET;
unset($list['exec'], $list['run']);
$p = array_search('jquploader', $list);
if ($p !== false)
unset ($list[$p]);
if (!isset($list['0']))
return false;
else {
$userid = intval($list['0']);
unset($list['0']);
} // else
$dir = implode('/', $list);
$dir = trim($dir, '/');
return array('userid' => $userid, 'dir' => $dir);
} // getDir
function getDirs() {
$list = $_GET;
unset($list['exec'], $list['run']);
$ret = array();
foreach($list as $key => $hand)
$ret[]= array('fulldir' => implode('/', array_slice($list, 0, $key + 1)), 'dir' => $hand);
return $ret;
} // getDirs
function getFileData() {
if (isset($_GET['0']) && checkUuid($_GET['0'])) {
$uuid = $_GET['0'];
$s = $this->Mysql->SelectSingle('files', null, array('id' => $uuid));
if (!empty($s))
return $s;
else
return false;
} // if
else
return false;
} // getFileData
function checkUpload($file) {
if ($file['error'] == 0){
if (($file['size'] / 1024) <= maxfilesize) {
if (($file['size'] / 1024) + $this->uinfo['size'] <= maxsize) {
if (is_uploaded_file($file['tmp_name']))
return true;
else
return false;
} // if
else
return false;
} // if
else
return false;
} // if
else
return false;
} // upload
function doFileUpload($file, $dir) {
$uploadfile = filedir . $this->uinfo['id'] . '/' . trim($dir, '/') . '/' . basename($file['name']);
if (!file_exists($uploadfile)) {
if (move_uploaded_file($file['tmp_name'], $uploadfile))
return true;
else
return false;
} // if
else
return false;
} // doFileUpload
function doFileUnUpload($file, $dir) {
unlink(filedir . $this->uinfo['id'] . '/' . trim($dir, '/') . '/' . basename($file['name']));
} // doFileUnUpload
function doDbUpload($file, $dir) {
mysql_query("UPDATE `user` SET `size` = `size` + " . round($file['size'] / 1024 ,2) . " WHERE `userid` = " . $this->uinfo['id']);
$sql = "INSERT INTO `files` SET
`id` = UUID(),
`fulldir` = '" . trim($dir, '/') . "',
`name` = '" . basename($file['name']) . "',
`uploaded` = '" . time() . "',
`user_id` = " . $this->uinfo['id'];
return mysql_query($sql);
} // doDbUpload
function doDbUploadUsr($file, $dir, $userid) {
mysql_query("UPDATE `user` SET `size` = `size` + " . round($file['size'] / 1024 ,2) . " WHERE `userid` = " . $userid);
$sql = "INSERT INTO `files` SET
`id` = UUID(),
`fulldir` = '" . trim($dir, '/') . "',
`name` = '" . basename($file['name']) . "',
`uploaded` = '" . time() . "',
`user_id` = " . $userid;
return mysql_query($sql);
} // doDbUploadUsr
function removeDirRecurive($filepath){
if (is_dir($filepath) && !is_link($filepath))
{
if ($dh = opendir($filepath))
{
while (($sf = readdir($dh)) !== false)
{
if ($sf == '.' || $sf == '..')
{
continue;
}
if (!$this->removeDirRecurive($filepath.'/'.$sf))
{
throw new Exception($filepath.'/'.$sf.' could not be deleted.');
}
}
closedir($dh);
}
return rmdir($filepath);
}
return unlink($filepath);
}
function renameFile($name) {
$a = array(' ', "\\", "'", "\/", '~', '!', '@', '#', '$', '%', '^', '&', '+', '|');
$b = array('_', "", "", "", '', '', '', '', '', '', '', '', '', '|');
$name = str_replace($a, $b, $name);
return $name;
} // renameFile
function public_dorip() {
mysql_connect('localhost', 'minimal', 'melodies') or die(mysql_error());
mysql_select_db('minimal_share') or die(mysql_error());
$list = $this->Mysql->Select('files');
mysql_connect('localhost', 'minimal', 'melodies') or die(mysql_error());
mysql_select_db('minimal_forum') or die(mysql_error());
$fulldir = '/home/minimal/public_html/imported/';
$newdir = '/home/minimal/public_html/failai/1/imported/';
foreach ($list as $key => $hand){
echo $fulldir . $hand['file'] . "<br />";
echo $newdir . $hand['name'] . "<br />";
if (file_exists($fulldir . $hand['file'])) {
if (rename($fulldir . $hand['file'], $newdir . $hand['name'])) {
$this->doDbUploadUsr($hand, '',1);
}
else
echo 'neina reneimint failo <br />';
}
else
echo 'nera tokio failo <br />';
}
}
} // class index
?>
Code: Select all
);
$this->Frame->assign('data', $data)
$dirs = $this->getDirs();
$dirs = array_slice($dirs, 0, sizeof($dirs) - 1);
$this->Frame->assign('dirs', $dirs);
$this->Frame->display('file', true, true);
} //im doing
Code: Select all
$this->Frame->assign('data', $data)
$find = "_";
$replace = " ";
$data['name'] = str_replace($find, $replace, $data['name']);
$dirs = $this->getDirs();
$dirs = array_slice($dirs, 0, sizeof($dirs) - 1);
$this->Frame->assign('dirs', $dirs);
$this->Frame->display('file', true, true);
} //im getting this error
Notice: Undefined property: index::$02-sydney_blu-senses_and_the_mind__olivier_giacomotto_remix.mp3 in /home/minimal/public_html/index/pages/index/index.obj.php on line 82