** Filename......: images.php
** Last changed..: 8 Mar 2003
Functions
- create a new folder,
- upload new image
Last changed by Fred Stuurman (fc.stuurman@hccnet.nl)
#$Id: images.php,v 1.1 2006/10/03 12:27:15 fstuurman Exp $
04-07-2006 , to make it work with Site@School 2.4.02
***********************************************************************/
include ("../../../configuration/database.inc.php"); // connecting to database
mysql_connect("$db_server", "$db_username", "$db_password");
mysql_select_db("$db_name");
require ("../../../core/session.php"); //build a session
require ("../../../core/common.inc.php"); //common fuctions
$query = "SELECT config_value FROM $table_configuration WHERE config_key='sessioncode'";
if ($result = mysql_query($query))
{
$check_sessioncode = mysql_result($result, 0);
unset ($query);
unset ($result);
}
if ($_SESSION['sessioncode'] != "$check_sessioncode")
{
//if we don't have a session present the login screen
Header("Location: ../../../index.php");
exit;
}
$query = "SELECT config_value FROM $table_configuration WHERE config_key='language'";
$result = mysql_query($query) or die_script(mysql_error());
$sas_language = mysql_result($result, 0);
include ("../../../languages/$sas_language/$sas_language.php");
unset ($query);
unset ($result);
$query = "SELECT config_value FROM $table_configuration WHERE config_key='serverpath'";
$result = mysql_query($query) or die_script(mysql_error());
$server_path = mysql_result($result, 0);
if (strrpos($server_path, '/') != strlen($server_path) - 1)
{
$server_path .= '/';
} //add last slash if not present
unset ($query);
unset ($result);
$query = "SELECT config_value FROM $table_configuration WHERE config_key='user_path'";
$result = mysql_query($query) or die_script(mysql_error());
$user_path = mysql_result($result, 0);
if (substr($user_path, 0, 1) == "/")
{
$user_path = substr($user_path, 1); //strip first slash
}
unset ($query);
unset ($result);
$query = "SELECT config_value FROM $table_configuration WHERE config_key='media_dir'";
$result = mysql_query($query) or die_script(mysql_error());
$media = mysql_result($result, 0);
unset ($query);
unset ($result);
//print "Serverpath: ".$server_path." Userpath: ".$user_path ;
$query = "SELECT config_value FROM $table_configuration WHERE config_key='file_permissions'";
$result = mysql_query($query) or die_script(mysql_error());
$perm = mysql_result($result, 0);
unset ($query);
unset ($result);
$BASE_DIR = $server_path;
$BASE_ROOT = $user_path . '/' . $media;
$BASE_URL .= '/';
$IMG_ROOT = $BASE_ROOT;
if (isset ($_GET['dir']))
{
$dirParam = $_GET['dir'];
if (strlen($dirParam) > 0)
{
if (substr($dirParam, 0, 1) == '/')
$IMG_ROOT .= $dirParam;
else
$IMG_ROOT = $dirParam;
}
}
$refresh_dirs = false;
$clearUploads = false;
if (strrpos($IMG_ROOT, '/') != strlen($IMG_ROOT) - 1)
$IMG_ROOT .= '/';
if (isset ($_GET['create']) && isset ($_GET['dir']))
{
create_folder();
}
if (isset ($_FILES['upload']) && is_array($_FILES['upload']) && isset ($_POST['dirPath']))
{
$dirPathPost = $_POST['dirPath'];
if (strlen($dirPathPost) > 0)
{
if (substr($dirPathPost, 0, 1) == '/')
{
$IMG_ROOT .= $dirPathPost;
}
else
$IMG_ROOT = $dirPathPost;
}
if (strrpos($IMG_ROOT, '/') != strlen($IMG_ROOT) - 1)
$IMG_ROOT .= '/';
do_upload($_FILES['upload'], $media . $dirPathPost);
}
function dir_name($dir)
{
$lastSlash = intval(strrpos($dir, '/'));
if ($lastSlash == strlen($dir) - 1)
{
return substr($dir, 0, $lastSlash);
}
else
return dirname($dir);
}
function do_upload($file, $dest_dir)
{
global $clearUploads;
if (is_file($file['tmp_name']))
{
$file_name = $file['name'];
sas_move_uploaded_file($dest_dir, $file_name, $file['tmp_name']);
//move_uploaded_file($file['tmp_name'], $dest_dir.$file_name);
}
$clearUploads = true;
}
function create_folder()
{
global $BASE_DIR, $IMG_ROOT, $refresh_dirs;
$folder_name = $_GET['foldername'];
if (strlen($folder_name) > 0)
{
$folder = $BASE_DIR . $IMG_ROOT . $folder_name;
if (!is_dir($folder) && !is_file($folder))
{
mkdir($folder, 0755);
$refresh_dirs = true;
}
}
}
function num_files($dir)
{
$total = 0;
if (is_dir($dir))
{
$d = @ dir($dir);
while (false !== ($entry = $d->read()))
{
//echo $entry."
";
if (substr($entry, 0, 1) != '.')
{
$total++;
}
}
$d->close();
}
return $total;
}
function dirs($dir, $abs_path)
{
$d = dir($dir);
//echo "Handle: ".$d->handle."
\n";
//echo "Path: ".$d->path."
\n";
$dirs = array ();
while (false !== ($entry = $d->read()))
{
if (is_dir($dir . '/' . $entry) && substr($entry, 0, 1) != '.')
{
//dirs($dir.'/'.$entry, $prefix.$prefix);
//echo $prefix.$entry."
\n";
$path['path'] = $dir . '/' . $entry;
$path['name'] = $entry;
$dirs[$entry] = $path;
}
}
$d->close();
ksort($dirs);
for ($i = 0; $i < count($dirs); $i++)
{
$name = key($dirs);
$current_dir = $abs_path . '/' . $dirs[$name]['name'];
echo ", \"$current_dir\"\n";
dirs($dirs[$name]['path'], $current_dir);
next($dirs);
}
}
function parse_size($size)
{
if ($size < 1024)
return $size . ' btyes';
else
if ($size >= 1024 && $size < 1024 * 1024)
{
return sprintf('%01.2f', $size / 1024.0) . ' Kb';
}
else
{
return sprintf('%01.2f', $size / (1024.0 * 1024)) . ' Mb';
}
}
function show_image($img, $file, $info, $size)
{
global $BASE_DIR, $BASE_URL, $newPath;
$img_path = dir_name($img);
$img_file = basename($img);
$img_url = $BASE_URL . $img_path . '/' . $img_file;
$filesize = parse_size($size);
?>
|
|
Configuration Problem: "" does not exist. |
';
echo '';
}
function draw_table_footer()
{
echo '
';
echo '';
}
?>
Untitled Document
0)
{
$upDirPath .= $path . '/';
}
}
$slashIndex = strlen($dirPath);
$newPath = $dirPath;
if ($slashIndex > 1 && substr($dirPath, $slashIndex -1, $slashIndex) == '/')
{
$newPath = substr($dirPath, 0, $slashIndex -1);
}
?>
';
$IMG_ROOT = ereg_replace("//", "/", $IMG_ROOT); // strip an extra slash from the image root
$d = @ dir($BASE_DIR . $IMG_ROOT);
if ($d)
{
//var_dump($d);
$images = array ();
$folders = array ();
while (false !== ($entry = $d->read()))
{
$img_file = $IMG_ROOT . $entry;
if (is_file($BASE_DIR . $img_file))
{
$image_info = @ getimagesize($BASE_DIR . $img_file);
if (is_array($image_info))
{
$file_details['file'] = $img_file;
$file_details['img_info'] = $image_info;
$file_details['size'] = filesize($BASE_DIR . $img_file);
$images[$entry] = $file_details;
//show_image($img_file, $entry, $image_info);
}
}
else
if (is_dir($BASE_DIR . $img_file) && substr($entry, 0, 1) != '.')
{
$folders[$entry] = $img_file;
//show_dir($img_file, $entry);
}
}
$d->close();
$counter = 1;
if (count($images) > 0 || count($folders) > 0)
{
//now sort the folders and images by name.
ksort($images);
ksort($folders);
draw_table_header();
for ($i = 0; $i < count($folders); $i++)
{
if ($counter == 6) //next row
{
print "";
$counter = 1;
}
$folder_name = key($folders);
show_dir($folders[$folder_name], $folder_name);
next($folders);
$counter++;
}
for ($i = 0; $i < count($images); $i++)
{
if ($counter == 6) //next row
{
print "
";
$counter = 1;
}
$image_name = key($images);
show_image($images[$image_name]['file'], $image_name, $images[$image_name]['img_info'], $images[$image_name]['size']);
next($images);
$counter++;
}
draw_table_footer();
}
else
{
draw_no_results($sas_lang['emptydir']);
}
}
else
{
draw_no_dir();
}
?>