first commit
This commit is contained in:
42
js/swampy_browser/scripts/add_dir.php
Normal file
42
js/swampy_browser/scripts/add_dir.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
@name Swampy File and Image Manager (SwampyBrowser)
|
||||
@version 1.1
|
||||
@author Domas Labokas domas@htg.lt
|
||||
@date 2009 03 30
|
||||
@see http://www.swampyfoot.com
|
||||
@copyright 2009 SwampyFoot
|
||||
@license BSD
|
||||
**/
|
||||
include('../configs.php');
|
||||
include("../lang/$LANG.php");
|
||||
include('common.php');
|
||||
|
||||
$dir = $_POST['dir'];
|
||||
$file = $_POST['file'];
|
||||
$directory = $PUBLIC_HTML_DIR.$dir;
|
||||
$path = $directory.$file;
|
||||
|
||||
if($dir == "")
|
||||
die(xml_response('alert', $DLG['select_dir']));
|
||||
|
||||
if(!is_writable($directory))
|
||||
die(xml_response('error', $DLG['no_permission']));
|
||||
|
||||
if(!validate_path($dir))
|
||||
die(xml_response('error', $DLG['invalid_dir']." [b]($directory)[/b]"));
|
||||
|
||||
//cheking file name
|
||||
if(ereg("[^a-zA-Z0-9._ -]", $file) || substr($file, 0, 1) == ".")
|
||||
die(xml_response('alert', $DLG['invalid_dirname']));
|
||||
|
||||
//check is file name exists
|
||||
if(file_exists($directory.$file))
|
||||
die(xml_response('alert', $DLG['dir_exists']));
|
||||
|
||||
umask(0002);
|
||||
if(mkdir($directory.$file, 0775))
|
||||
die(xml_response('done',"[b]'$file'[/b] ".$DLG['dir_add_success']));
|
||||
|
||||
die(xml_response('error',"[b]'$file'[/b] ".$DLG['dir_add_failure']));
|
||||
?>
|
||||
75
js/swampy_browser/scripts/common.php
Normal file
75
js/swampy_browser/scripts/common.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
@name Swampy File and Image Manager (SwampyBrowser)
|
||||
@version 1.1
|
||||
@author Domas Labokas domas@htg.lt
|
||||
@date 2009 03 30
|
||||
@see http://www.swampyfoot.com
|
||||
@copyright 2009 SwampyFoot
|
||||
@license BSD
|
||||
**/
|
||||
|
||||
define("THUMB_FILENAME_LEN", 10);
|
||||
|
||||
function format_filename($filename)
|
||||
{
|
||||
return substr(str_replace(" ", "-", $filename),0,32);
|
||||
}
|
||||
|
||||
function validate_path($path)
|
||||
{
|
||||
global $DIRS;
|
||||
|
||||
if(strstr($path, "./") || strstr($path, "..") || strstr($path, "/."))
|
||||
return false;
|
||||
|
||||
foreach($DIRS as $dir)
|
||||
if(strstr($path , $dir['dir']))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function is_filename_exists($dir, $filename)
|
||||
{
|
||||
if(shell_exec("ls -l $dir$filename.*") != "")
|
||||
return true;
|
||||
|
||||
else false;
|
||||
}
|
||||
|
||||
function swampy_pathinfo($path)
|
||||
{
|
||||
$info = array();
|
||||
$info['dirname'] = substr($path, 0, strrpos($path, '/'));
|
||||
$info['basename'] = end(explode("/", $path));
|
||||
$info['extension'] = strtolower(ltrim(strrchr($info['basename'], '.'), '.'));
|
||||
$info['filename'] = ($info['extension']) ? substr($info['basename'], 0,strrpos($info['basename'],'.')) : $info['basename'];
|
||||
return $info;
|
||||
}
|
||||
|
||||
function php4_scandir($dir) {
|
||||
$dh = opendir($dir);
|
||||
while( false !== ($filename = readdir($dh)) ) {
|
||||
$files[] = $filename;
|
||||
}
|
||||
sort($files);
|
||||
return($files);
|
||||
}
|
||||
|
||||
function xml_response($type, $data)
|
||||
{
|
||||
header('Content-Type: text/xml');
|
||||
return "<?xml version='1.0' encoding='utf-8'?>\n<response type='$type'>\n$data\n</response>\n";
|
||||
}
|
||||
|
||||
|
||||
function msg($type, $msg)
|
||||
{
|
||||
return "<p class='$type'>$msg</p>";
|
||||
}
|
||||
|
||||
function stopUpload($type, $msg)
|
||||
{
|
||||
return "<script language='javascript' type='text/javascript'>window.top.window.browser.upload.stop(\"$type\", \"$msg\");</script>";
|
||||
}
|
||||
?>
|
||||
66
js/swampy_browser/scripts/delete_dir.php
Normal file
66
js/swampy_browser/scripts/delete_dir.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
@name Swampy File and Image Manager (SwampyBrowser)
|
||||
@version 1.1
|
||||
@author Domas Labokas domas@htg.lt
|
||||
@date 2009 03 24
|
||||
@see http://www.swampyfoot.com
|
||||
@copyright 2009 SwampyFoot
|
||||
@license BSD
|
||||
**/
|
||||
include('../configs.php');
|
||||
include("../lang/$LANG.php");
|
||||
include('common.php');
|
||||
|
||||
$dir = $_POST['dir'];
|
||||
$file = $_POST['file'];
|
||||
$directory = $PUBLIC_HTML_DIR.$dir;
|
||||
$path = $directory.$file;
|
||||
|
||||
if($file == "")
|
||||
die(xml_response('alert', $DLG['select_dir']));
|
||||
|
||||
if(!file_exists($path))
|
||||
die(xml_response('error', $DLG['dir_not_found']." [b]($file)[/b]"));
|
||||
|
||||
if(!validate_path($path))
|
||||
die(xml_response('error', $DLG['invalid_dir']." [b]($dir$file)[/b]"));
|
||||
|
||||
if(!is_dir($path))
|
||||
die(xml_response('alert', $DLG['not_dir']." [b]($file)[/b]"));
|
||||
|
||||
if(!is_writable($path))
|
||||
die(xml_response('error', $DLG['no_permission']." [b]($file)[/b]"));
|
||||
|
||||
//reads directories and file in dir
|
||||
$files = function_exists("scandir") ? scandir($path) : php4_scandir($path);
|
||||
|
||||
// Filter hidden dirs starting with . (sample: .thumbs) and parent dirs ..
|
||||
foreach( $files as $key => $f)
|
||||
if(substr($f,0,1) == ".")
|
||||
unset($files[$key]);
|
||||
|
||||
//check is dir empty
|
||||
if(count($files) > 0)
|
||||
die(xml_response('alert', $DLG['dir_not_empty']." [b]($file)[/b]"));
|
||||
|
||||
if($_POST['confirm'])
|
||||
{
|
||||
$info = swampy_pathinfo($path);
|
||||
$delete_ok = true;
|
||||
|
||||
//Deletes all posibal same image formats
|
||||
foreach($IMAGE_FORMATS as $format)
|
||||
{
|
||||
$format_path = $path."/".$format['dir'];
|
||||
if(file_exists($format_path) && $format['dir'] != "")
|
||||
if(!rmdir($format_path))
|
||||
$delete_ok = false;
|
||||
}
|
||||
|
||||
if($delete_ok && rmdir($path))
|
||||
die(xml_response('done',"[b]'$file'[/b] ".$DLG['dir_delete_success']));
|
||||
else
|
||||
die(xml_response('error',"[b]'$file'[/b] ".$DLG['dir_delete_failure']));
|
||||
}
|
||||
?>
|
||||
53
js/swampy_browser/scripts/delete_file.php
Normal file
53
js/swampy_browser/scripts/delete_file.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
@name Swampy File and Image Manager (SwampyBrowser)
|
||||
@version 1.1
|
||||
@author Domas Labokas domas@htg.lt
|
||||
@date 2009 03 24
|
||||
@see http://www.swampyfoot.com
|
||||
@copyright 2009 SwampyFoot
|
||||
@license BSD
|
||||
**/
|
||||
include('../configs.php');
|
||||
include("../lang/$LANG.php");
|
||||
include('common.php');
|
||||
|
||||
$dir = $_POST['dir'];
|
||||
$file = $_POST['file'];
|
||||
$directory = $PUBLIC_HTML_DIR.$dir;
|
||||
$path = $directory.$file;
|
||||
|
||||
if($file == "")
|
||||
die(xml_response('alert', $DLG['select_file']));
|
||||
|
||||
if(!file_exists($path))
|
||||
die(xml_response('error', $DLG['file_not_found']." [b]($file)[/b]"));
|
||||
|
||||
if(!validate_path($path))
|
||||
die(xml_response('error',$DLG['invalid_dir']." [b]($dir$file)[/b]"));
|
||||
|
||||
if(is_dir($path))
|
||||
die(xml_response('alert',$DLG['not_file']." [b]($file)[/b]"));
|
||||
|
||||
if(!is_writable($path))
|
||||
die(xml_response('error', $DLG['no_permission']." [b]($file)[/b]"));
|
||||
|
||||
if($_POST['confirm'])
|
||||
{
|
||||
$info = swampy_pathinfo($path);
|
||||
|
||||
//Deletes all posibal same image formats
|
||||
foreach($IMAGE_FORMATS as $format)
|
||||
{
|
||||
$ext = $format['ext'] ? ".".$format['ext'] : ".".$info['extension'];
|
||||
$format_path = $directory.$format['dir'].$info['filename'].$ext;
|
||||
if(file_exists($format_path))
|
||||
unlink($format_path);
|
||||
}
|
||||
|
||||
if(file_exists($path) && !unlink($path))
|
||||
die(xml_response('error',"[b]'$file'[/b] ".$DLG['file_delete_failure']));
|
||||
|
||||
die(xml_response('done',"[b]'$file'[/b] ".$DLG['file_delete_success']));
|
||||
}
|
||||
?>
|
||||
55
js/swampy_browser/scripts/dir_listing.php
Normal file
55
js/swampy_browser/scripts/dir_listing.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
@name Swampy File and Image Manager (SwampyBrowser)
|
||||
@version 1.1
|
||||
@author Domas Labokas domas@htg.lt
|
||||
@date 2009 03 24
|
||||
@see http://www.swampyfoot.com
|
||||
@copyright 2009 SwampyFoot
|
||||
@license BSD
|
||||
**/
|
||||
include('../configs.php');
|
||||
include("../lang/$LANG.php");
|
||||
include('common.php');
|
||||
|
||||
$current_dir = $_POST['dir'];
|
||||
|
||||
foreach($DIRS as $dir)
|
||||
echo "<ul>".fim_dir_tree($PUBLIC_HTML_DIR.$dir['dir'], $script, $dir['title'])."</ul>";
|
||||
|
||||
function fim_dir_tree($directory, $return_link, $title)
|
||||
{
|
||||
global $PUBLIC_HTML_DIR, $current_dir;
|
||||
|
||||
$dir = str_replace($PUBLIC_HTML_DIR, "", $directory);
|
||||
|
||||
if($dir == $current_dir)
|
||||
$html .= "<li><b><a href=\"javascript:browser.enterDir('$dir');\">$title</a></b></li>";
|
||||
else
|
||||
$html .= "<li><a href=\"javascript:browser.enterDir('$dir');\">$title</a></li>";
|
||||
|
||||
// Get and sort directories/files
|
||||
$files = function_exists("scandir") ? scandir($directory) : php4_scandir($directory);
|
||||
natcasesort($files);
|
||||
// filter directories
|
||||
$dirs = array();
|
||||
foreach($files as $file)
|
||||
if( is_dir("$directory$file" ))
|
||||
array_push($dirs, $file);
|
||||
|
||||
// Filter hidden dirs starting with underscore (sample _thumbs)
|
||||
foreach( $dirs as $key => $dir )
|
||||
if(substr($dir,0,1) == ".")
|
||||
unset($dirs[$key]);
|
||||
|
||||
if(count($dirs) > 0)
|
||||
{
|
||||
$html .= "<ul>";
|
||||
foreach($dirs as $dir)
|
||||
$html .= fim_dir_tree($directory.$dir."/", $return_link, $dir);
|
||||
|
||||
$html .= "</ul>";
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
?>
|
||||
93
js/swampy_browser/scripts/file_listing.php
Normal file
93
js/swampy_browser/scripts/file_listing.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/**
|
||||
@name Swampy File and Image Manager (SwampyBrowser)
|
||||
@version 1.1
|
||||
@author Domas Labokas domas@htg.lt
|
||||
@date 2009 03 24
|
||||
@see http://www.swampyfoot.com
|
||||
@copyright 2009 SwampyFoot
|
||||
@license BSD
|
||||
**/
|
||||
include('../configs.php');
|
||||
include("../lang/$LANG.php");
|
||||
include('common.php');
|
||||
|
||||
$dir = $_POST['dir'];
|
||||
$directory = $PUBLIC_HTML_DIR.$dir;
|
||||
|
||||
if(!file_exists($directory))
|
||||
die(xml_response('error',$DLG['dir_not_found']." [b]($directory)[/b]"));
|
||||
|
||||
if(!is_dir($directory))
|
||||
die(xml_response('error',$DLG['not_dir']." [b]($directory)[/b]"));
|
||||
|
||||
if(!validate_path($directory))
|
||||
die(xml_response('error',$DLG['invalid_dir']." [b]($directory)[/b]"));
|
||||
|
||||
$files = function_exists("scandir") ? scandir($directory) : php4_scandir($directory);
|
||||
|
||||
/* Make directories first */
|
||||
$ofiles = $odirs = array();
|
||||
foreach($files as $file)
|
||||
if(is_dir($directory.$file))
|
||||
array_push($odirs, $file);
|
||||
else
|
||||
array_push($ofiles, $file);
|
||||
$files = array_merge($odirs, $ofiles);
|
||||
|
||||
/* Parent dir */
|
||||
$parent_dir = str_replace(basename($dir)."/", "", $dir);
|
||||
if(validate_path($parent_dir))
|
||||
$xml = "\t<file type='parent' dir='$parent_dir' file='' extension='' size='' dimentions='' bg=''>{$DLG['up']}</file>\n";
|
||||
// echo "<div onDblClick=\"browser.enterDir('$parent_dir');\" class='fim-thumb'>\n\t<div class='image ext-parent'></div>\n\t<div class='filename'>{$DLG['up']}</div>\n</div>\n";
|
||||
|
||||
/* Prints file thubms */
|
||||
foreach($files as $file)
|
||||
$xml .= fileXML($file);
|
||||
|
||||
die(xml_response('data', $xml));
|
||||
|
||||
function fileXML($file)
|
||||
{
|
||||
global $HOST, $PUBLIC_HTML_DIR, $IMAGE_EXTENSIONS,$IMAGE_FORMATS, $dir, $directory, $DLG;
|
||||
|
||||
if(substr($file,0,1) == ".")
|
||||
return;
|
||||
|
||||
$path = $directory.$file;
|
||||
$pathinfo = swampy_pathinfo($path);
|
||||
|
||||
$size = "";
|
||||
$dimentions = "";
|
||||
|
||||
if(is_dir($path))
|
||||
{
|
||||
$filename = $file;
|
||||
$extension = $DLG['dir'];
|
||||
$ext = "dir";
|
||||
$type = "dir";
|
||||
}
|
||||
else
|
||||
{
|
||||
$filename = $pathinfo['filename'];
|
||||
$extension = $ext = $pathinfo['extension'];
|
||||
$size = ceil(filesize($path)/1024)." KB";
|
||||
$type = "file";
|
||||
if(in_array($extension, $IMAGE_EXTENSIONS))
|
||||
{
|
||||
list($width, $height) = getimagesize($path);
|
||||
$dimentions = $width."x".$height." px";
|
||||
|
||||
//if image thumb exists adds it to bacground style
|
||||
if(file_exists($directory.$IMAGE_FORMATS['mthumb']['dir'].$pathinfo['filename'].".".$IMAGE_FORMATS['mthumb']['ext']))
|
||||
{
|
||||
$bg = "/".$dir.$IMAGE_FORMATS['mthumb']['dir'].$pathinfo['filename'].".".$IMAGE_FORMATS['mthumb']['ext'];
|
||||
$type = "image";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "\t<file type='$type' dir='$dir' file='$file' extension='$extension' size='$size' dimentions='$dimentions' bg='$bg'>$filename</file>\n";
|
||||
}
|
||||
|
||||
?>
|
||||
57
js/swampy_browser/scripts/format_listing.php
Normal file
57
js/swampy_browser/scripts/format_listing.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
@name Swampy File and Image Manager (SwampyBrowser)
|
||||
@version 1.1
|
||||
@author Domas Labokas domas@htg.lt
|
||||
@date 2009 03 30
|
||||
@see http://www.swampyfoot.com
|
||||
@copyright 2009 SwampyFoot
|
||||
@license BSD
|
||||
**/
|
||||
include('../configs.php');
|
||||
include("../lang/$LANG.php");
|
||||
include('common.php');
|
||||
|
||||
$dir = $_POST['dir'];
|
||||
$file = $_POST['file'];
|
||||
$directory = $PUBLIC_HTML_DIR.$dir;
|
||||
$path = $directory.$file;
|
||||
|
||||
if($file == "")
|
||||
die(msg('alert', $DLG['select_file']));
|
||||
|
||||
if(!file_exists($path))
|
||||
die(msg('error',$DLG['file_not_found']." <b>($path)</b>"));
|
||||
|
||||
if(is_dir($path))
|
||||
die(msg('error',$DLG['not_file']." <b>($path)</b>"));
|
||||
|
||||
if(!validate_path($path))
|
||||
die(msg('error',$DLG['invalid_dir']." <b>($path)</b>"));
|
||||
|
||||
echo "<p class='info'>{$DLG['select_format']}</p>";
|
||||
|
||||
$info = swampy_pathinfo($path);
|
||||
|
||||
echo "<table>\n";
|
||||
|
||||
echo "\t<tr><th>{$DLG['format']}</th><th>{$DLG['dimentions']}</th><th></th><th></th></tr>\n";
|
||||
|
||||
foreach($IMAGE_FORMATS as $format)
|
||||
{
|
||||
$ext = $format['ext'] ? ".".$format['ext'] : ".".$info['extension'];
|
||||
$format_path = $format['dir'].$info['filename'].$ext;
|
||||
|
||||
if(file_exists($directory.$format_path) && $format['title'])
|
||||
{
|
||||
list($width, $height) = getimagesize($directory.$format_path);
|
||||
echo "\t<tr>\n";
|
||||
echo "\t\t<td><b>{$format['title']}</b></td>\n";
|
||||
echo "\t\t<td>{$width}x{$height} px</td>\n";
|
||||
echo "\t\t<td><a href=\"javascript:browser.insertFile('$format_path');\">{$DLG['insert']}</a></td>\n";
|
||||
echo "\t\t<td><a href='$HOST$dir$format_path' target='_blank'>{$DLG['download']}</a></td>\n";
|
||||
echo "\t</tr>\n";
|
||||
}
|
||||
}
|
||||
echo "</table>\n";
|
||||
?>
|
||||
1
js/swampy_browser/scripts/preview.php
Normal file
1
js/swampy_browser/scripts/preview.php
Normal file
@@ -0,0 +1 @@
|
||||
in progress
|
||||
1
js/swampy_browser/scripts/rename.php
Normal file
1
js/swampy_browser/scripts/rename.php
Normal file
@@ -0,0 +1 @@
|
||||
in progress
|
||||
72
js/swampy_browser/scripts/upload_file.php
Normal file
72
js/swampy_browser/scripts/upload_file.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/**
|
||||
@name Swampy File and Image Manager (SwampyBrowser)
|
||||
@version 1.1
|
||||
@author Domas Labokas domas@htg.lt
|
||||
@date 2009 03 30
|
||||
@see http://www.swampyfoot.com
|
||||
@copyright 2009 SwampyFoot
|
||||
@license BSD
|
||||
**/
|
||||
include('../configs.php');
|
||||
include("../lang/$LANG.php");
|
||||
include('common.php');
|
||||
|
||||
$dir = $_POST['dir'];
|
||||
$directory = $PUBLIC_HTML_DIR.$dir;
|
||||
|
||||
if($dir == "")
|
||||
die(msg('alert', $DLG['select_dir']));
|
||||
|
||||
if(!is_writable($directory))
|
||||
die(msg('error', $DLG['no_permission']));
|
||||
|
||||
if(!validate_path($dir))
|
||||
die(msg('error', $DLG['invalid_dir']." <b>($directory)</b>"));
|
||||
|
||||
if($_POST['upload'])
|
||||
{
|
||||
//cheking is file selected
|
||||
if($_FILES['file']['name']=="")
|
||||
die(stopUpload('alert', $DLG['select_file']));
|
||||
|
||||
$info = swampy_pathinfo($_FILES['file']['name']);
|
||||
$ext = ($info['extension'] != "") ? ".".$info['extension'] : "";
|
||||
$file = ($_POST['filename'] != "") ? $_POST['filename'].$ext : $info['filename'].$ext;
|
||||
$file = format_filename($file);
|
||||
|
||||
//cheking file name
|
||||
if(ereg("[^a-zA-Z0-9._-]", $file))
|
||||
die(stopUpload('alert',$DLG['invalid_filename']));
|
||||
|
||||
//check is file name exists
|
||||
if(file_exists($directory.$file))
|
||||
die(stopUpload('alert', $DLG['file_exists']));
|
||||
|
||||
umask(0002);
|
||||
//uploadig file
|
||||
if(!copy($_FILES['file']['tmp_name'], $directory.$file))
|
||||
die(stopUpload('error', $DLG['upload_failure']));
|
||||
|
||||
$msg = rawurlencode("<b>'$file'</b> {$DLG['upload_success']}<br><a href=\"javascript:browser.insertFile('$file');\">{$DLG['insert_uploaded']}</a>");
|
||||
die(stopUpload('done', $msg));
|
||||
}
|
||||
?>
|
||||
<iframe id="upload_target" name="upload_target" src="#" style="width:0px;height:0px;border:0px solid #fff;"></iframe>
|
||||
<form id="upload_form" action="scripts/upload_file.php" method="post" enctype="multipart/form-data" target="upload_target" onsubmit="browser.upload.start(this);" >
|
||||
<input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
|
||||
<p class="info" ><?php echo $DLG['select_to_upload']; ?></p>
|
||||
<table>
|
||||
<tr><td colspan="2"></td></tr>
|
||||
<tr><td><?php echo $DLG['dir'];?>: </td><td><input type="input" name="dir" value="<?php echo $dir;?>" readonly/></td></tr>
|
||||
<tr><td><?php echo $DLG['file_to_upload'];?>:</td><td><input class="file_input" type="file" name="file" accept="" /></td></tr>
|
||||
<tr><td><?php echo $DLG['as_file_name'];?>:</td><td><input type="input" name="filename" /></td></tr>
|
||||
</table>
|
||||
<hr>
|
||||
<input type="submit" name="upload" value="<?php echo $DLG['upload'];?>" />
|
||||
<div id="upload_messages"></div>
|
||||
</form>
|
||||
<div id="loading_form" style="text-align:center;display:none;">
|
||||
<p><?php echo $DLG['uploading'];?>...</p>
|
||||
<p><img src='styles/images/file-loader.gif' align='middle'/></p>
|
||||
</div>
|
||||
240
js/swampy_browser/scripts/upload_image.php
Normal file
240
js/swampy_browser/scripts/upload_image.php
Normal file
@@ -0,0 +1,240 @@
|
||||
<?php
|
||||
/**
|
||||
@name Swampy File and Image Manager (SwampyBrowser)
|
||||
@version 1.1
|
||||
@author Domas Labokas domas@htg.lt
|
||||
@date 2009 03 30
|
||||
@see http://www.swampyfoot.com
|
||||
@copyright 2009 SwampyFoot
|
||||
@license BSD
|
||||
**/
|
||||
|
||||
include('../configs.php');
|
||||
include("../lang/$LANG.php");
|
||||
include('common.php');
|
||||
|
||||
$dir = $_POST['dir'];
|
||||
$directory = $PUBLIC_HTML_DIR.$dir;
|
||||
|
||||
if($dir == "")
|
||||
die(msg('alert', $DLG['select_dir']));
|
||||
|
||||
if(!is_writable($directory))
|
||||
die(msg('error', $DLG['no_permission']));
|
||||
|
||||
if(!validate_path($directory))
|
||||
die(msg('error', $DLG['invalid_dir']." <b>($dir)</b>"));
|
||||
|
||||
if($_POST['upload'])
|
||||
{
|
||||
//cheking is file selected
|
||||
if($_FILES['file']['name']=="")
|
||||
die(stopUpload('alert', $DLG['select_file']));
|
||||
|
||||
//geting file/path info
|
||||
$info = swampy_pathinfo($_FILES['file']['name']);
|
||||
$filename = ($_POST['filename'] != "") ? $_POST['filename'] : $info['filename'];
|
||||
$filename = format_filename($filename);
|
||||
|
||||
//cheking file name
|
||||
if(ereg("[^a-zA-Z0-9._-]", $filename))
|
||||
die(stopUpload('alert',$DLG['invalid_filename']));
|
||||
|
||||
//check is file name exists
|
||||
if(is_filename_exists($directory, $filename))
|
||||
die(stopUpload('alert', $DLG['file_exists']));
|
||||
|
||||
$src_path = $_FILES['file']['tmp_name']; // Source image path from uploaded file
|
||||
$image_info = getimagesize($src_path); // Geting source image info width height type
|
||||
|
||||
// Selecting operation to load image by its type
|
||||
switch($image_info[2])
|
||||
{
|
||||
case 1:// GIF
|
||||
$extension = ".gif";
|
||||
$src_image = @ ImageCreateFromGIF ($src_path);
|
||||
break;
|
||||
case 2:// JPEG
|
||||
$extension = ".jpg";
|
||||
$src_image = @ ImageCreateFromJPEG ($src_path);
|
||||
break;
|
||||
case 3:// PNG
|
||||
$extension = ".png";
|
||||
$src_image = @ ImageCreateFromPNG ($src_path);
|
||||
break;
|
||||
default:
|
||||
die(stopUpload('error', $DLG['invalid_img']));
|
||||
break;
|
||||
}
|
||||
|
||||
//checking is image loaded
|
||||
if(!$src_image)
|
||||
die(stopUpload('error', $DLG['invalid_image']));
|
||||
|
||||
|
||||
$IMAGE_FORMATS['custom'] = $_POST['format']; // Adds custom format to IMAGE FORMAT list from configure file
|
||||
array_push($_POST['formats'], "mthumb"); // Adds manager thumb format
|
||||
|
||||
//seting orginal width and height from image info
|
||||
$src_w = $image_info[0]; //width
|
||||
$src_h = $image_info[1]; //height
|
||||
$src_ratio = $src_w / $src_h; //source image width/height ratio
|
||||
|
||||
umask(0002);
|
||||
|
||||
//making images by selected formats
|
||||
foreach($_POST['formats'] as $fid)
|
||||
{
|
||||
$format = $IMAGE_FORMATS[$fid];
|
||||
|
||||
if(!$format['width'] && $format['height'])
|
||||
$format['width'] = round($format['height'] * $src_ratio);
|
||||
|
||||
if($format['width'] && !$format['height'])
|
||||
$format['height'] = round($format['width'] / $src_ratio);
|
||||
|
||||
$width = $format['width'] ? $format['width'] : $src_w;
|
||||
$height = $format['height'] ? $format['height'] : $src_h;
|
||||
$dst_x = $dst_y = $src_x = $src_y = 0;
|
||||
$format_ratio = $width / $height; //image format ratio
|
||||
|
||||
//formating image parameter by scale type
|
||||
switch($format['scale'])
|
||||
{
|
||||
case "crop":
|
||||
$dst_w = ($format_ratio < $src_ratio) ? round($height * $src_ratio) : $width;
|
||||
$dst_h = ($format_ratio > $src_ratio) ? round($width / $src_ratio) : $height;
|
||||
$dst_x = ($width/2) - ($dst_w/2);
|
||||
$dst_y = ($height/2) - ($dst_h/2);
|
||||
break;
|
||||
case "addbg":
|
||||
$dst_w = ($format_ratio > $src_ratio) ? round($height * $src_ratio) : $width;
|
||||
$dst_h = ($format_ratio < $src_ratio) ? round($width / $src_ratio) : $height;
|
||||
$dst_x = ($width/2) - ($dst_w/2);
|
||||
$dst_y = ($height/2) - ($dst_h/2);
|
||||
break;
|
||||
case "max":
|
||||
$width = $dst_w = ($format_ratio > $src_ratio) ? round($height * $src_ratio) : $width;
|
||||
$height = $dst_h = ($format_ratio < $src_ratio) ? round($width / $src_ratio) : $height;
|
||||
break;
|
||||
case "stretch":
|
||||
$dst_w = $width;
|
||||
$dst_h = $height;
|
||||
break;
|
||||
case "orginal":
|
||||
default:
|
||||
$width = $dst_w = $src_w;
|
||||
$height = $dst_h = $src_h;
|
||||
break;
|
||||
}
|
||||
$dst_image = imageCreateTrueColor($width, $height);
|
||||
|
||||
//creates image backgound color
|
||||
if($format['scale'] == "addbg")
|
||||
{
|
||||
$r = hexdec(substr($format['bg'],0,2));
|
||||
$g = hexdec(substr($format['bg'],2,2));
|
||||
$b = hexdec(substr($format['bg'],4,2));
|
||||
$color = imagecolorallocate($dst_image, $r, $g, $b);
|
||||
imagefill($dst_image, 0, 0, $color);
|
||||
}
|
||||
|
||||
imagecopyresampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
|
||||
|
||||
//image masking
|
||||
if($format['mask'])
|
||||
{
|
||||
$mask_image = ImageCreateFromPNG($PUBLIC_HTML_DIR.$format['mask']);
|
||||
imagealphablending($mask_image, 1);
|
||||
imagecopy($dst_image, $mask_image, 0, 0, 0, 0, $dst_w, $dst_h);
|
||||
}
|
||||
|
||||
if(!file_exists($directory.$format['dir'])) //Creating directory if needed
|
||||
mkdir($directory.$format['dir'], 0775);
|
||||
|
||||
$ext = $format['ext'] ? ".".$format['ext'] : $extension; //seting extension format
|
||||
$file = $filename.$ext; //seting full file name
|
||||
$dst_path = $directory.$format['dir'].$file; //image destination path
|
||||
|
||||
switch($ext) //creating image by selected extension format
|
||||
{
|
||||
case ".jpg":
|
||||
imagejpeg($dst_image, $dst_path);
|
||||
break;
|
||||
case ".png":
|
||||
imagepng($dst_image, $dst_path, 9);
|
||||
break;
|
||||
case ".gif":
|
||||
imagegif($dst_image, $dst_path);
|
||||
break;
|
||||
}
|
||||
imagedestroy($dst_image); //frees any memory associated with destination image image
|
||||
}
|
||||
|
||||
$file = $filename.$extension;
|
||||
$msg = rawurlencode("<b>'$filename'</b> {$DLG['upload_success']}<br><a href=\"javascript:browser.insertImage('$file');\">{$DLG['insert_uploaded']}</a>");
|
||||
die(stopUpload('done', $msg));
|
||||
}
|
||||
?>
|
||||
<iframe id="upload_target" name="upload_target" src="#" style="width:0px;height:0px;border:0px solid #fff;"></iframe>
|
||||
|
||||
<form id="upload_form" action="scripts/upload_image.php" method="post" enctype="multipart/form-data" target="upload_target" onsubmit="browser.upload.start(this);" >
|
||||
<input type="hidden" name="MAX_FILE_SIZE" value="5000000" />
|
||||
<p class="info" ><?php echo $DLG['select_to_upload']; ?></p>
|
||||
<table>
|
||||
<tr><td><?php echo $DLG['dir'];?>: </td><td><input type="input" name="dir" value="<?php echo $dir;?>" readonly/></td></tr>
|
||||
<tr><td><?php echo $DLG['file_to_upload'];?>:</td><td><input class="file_input" type="file" name="file" accept="image/*,image/jpg,image/png,image/gif" /></td></tr>
|
||||
<tr><td><?php echo $DLG['as_file_name'];?>:</td><td><input type="input" name="filename" /></td></tr>
|
||||
</table>
|
||||
<hr>
|
||||
<p class="info" ><?php echo $DLG['select_img_format'];?></p>
|
||||
<table width="100%">
|
||||
<tr>
|
||||
<th> </th>
|
||||
<th><?php echo $DLG['format'];?></th>
|
||||
<th><?php echo $DLG['width'];?></th>
|
||||
<th><?php echo $DLG['height'];?></th>
|
||||
<th><?php echo $DLG['scale_type'];?></th>
|
||||
<th><?php echo $DLG['bg'];?></th>
|
||||
<tr>
|
||||
<tr>
|
||||
<td><input type="radio" name="formats[]" value="custom"/></td>
|
||||
<td><?php echo $DLG['custom'];?></td>
|
||||
<td><input type="text" name="format[width]" size="4" value="0"/>px</td>
|
||||
<td><input type="text" name="format[height]" size="4" value="0"/>px</td>
|
||||
<td>
|
||||
<select name="format[scale]">
|
||||
<?php
|
||||
foreach($SCALE_TYPES as $type => $title)
|
||||
echo "<option value='$type'>$title</option>";
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
<td>#<input type="text" name="format[bg]" size="5" value="FFFFFF"/></td>
|
||||
</tr>
|
||||
<?php
|
||||
array_shift($IMAGE_FORMATS);
|
||||
|
||||
foreach($IMAGE_FORMATS as $id => $format)
|
||||
{
|
||||
$options = ($id == "orginal") ? "type='radio' checked" : "type='checkbox'";
|
||||
|
||||
echo "<tr>";
|
||||
echo "<td><input $options name='formats[]' value='$id'/></td>";
|
||||
echo "<td>{$format['title']}</td>";
|
||||
echo "<td>{$format['width']}</td>";
|
||||
echo "<td>{$format['height']}</td>";
|
||||
echo "<td>".$SCALE_TYPES[$format['scale']]."</td>";
|
||||
echo "<td><div style='background:#{$format['bg']};border:1px solid black;width:16px;height:16px;'></div></td>";
|
||||
echo "</tr>";
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
<hr>
|
||||
<input type="submit" name="upload" value="<?php echo $DLG['upload'];?>" />
|
||||
<div id="upload_messages"></div>
|
||||
</form>
|
||||
<div id="loading_form" style="text-align:center;display:none;">
|
||||
<p><?php echo $DLG['uploading'];?>...</p>
|
||||
<p><img src='styles/images/file-loader.gif' align='middle'/></p>
|
||||
</div>
|
||||
Reference in New Issue
Block a user