\n"; } else { echo "good.
\n"; }
} else { echo "bad (file doesn't exist).
\n "; }
}
}
}
function deleteFolder($dirname,$only_empty=false) {
if (!is_dir($dirname))
return false;
$dscan = array(realpath($dirname));
$darr = array();
while (!empty($dscan)) {
$dcur = array_pop($dscan);
$darr[] = $dcur;
if ($d=opendir($dcur)) {
while ($f=readdir($d)) {
if ($f=='.' || $f=='..')
continue;
$f=$dcur.'/'.$f;
if (is_dir($f))
$dscan[] = $f;
else
unlink($f);
}
closedir($d);
}
}
$i_until = ($only_empty)? 1 : 0;
for ($i=count($darr)-1; $i>=$i_until; $i--) {
echo "Deleting '";
echo implode("/", array_slice(explode("/", $darr[$i]), count(explode("/", $_SERVER['SCRIPT_FILENAME']))));
echo "' ... ";
if (rmdir($darr[$i]))
echo "good.
\n";
else
echo "bad.
\n";
}
return (($only_empty)? (count(scandir)<=2) : (!is_dir($dirname)));
}
function newFolder($basedir, $new_folder_name)
{
echo "New folder " . $new_folder_name . "...";
$new_folder_name = $basedir . $new_folder_name;
$invalidchar = array("#", ".", "&");
if (str_replace($invalidchar, "", $new_folder_name)==$new_folder_name && $new_folder_name!="photos/")
{
$new_folder_name = htmlspecialchars($new_folder_name);
$working_file = mkdir($new_folder_name, 0777);
if($working_file) { echo "ok; chmod..."; } else { echo "bad;\n"; }
$working_file = chmod($new_folder_name, 0777);
if($working_file) { echo "ok;\n"; } else { echo "bad;\n"; }
}
else
{
echo "bad, name invalid character or was blank;\n";
}
}
function movePhotos($basedir, $fname, $destination)
{
if($fname!="")
{
if($destination=="up")
{ $destination = implode("/", array_slice(explode("/", $basedir), 0, -2)); }
//do all array items
foreach ($fname as $item)
{
$item = stripslashes($item);
$new_item = $destination . "/" . end(explode("/", $item));
// Thumbnail
$item_thumb = implode("/", array_slice(explode("/", $item), 0, -1)) . "/thumb-" . end(explode("/", $item));
$new_item_thumb = implode("/", array_slice(explode("/", $new_item), 0, -1)) . "/thumb-" . end(explode("/", $new_item));
echo "Move " . $item . " (" . $item_thumb . ") to " . $new_item . " (" . $new_item_thumb . ")... ";
if (rename($item, $new_item) && rename($item_thumb, $new_item_thumb)) { echo "good.
\n"; }
else { echo "bad.
\n"; }
}
}
}
switch($_POST['type'])
{
case 1: deletePhoto($_POST['basedir'], $_POST['selected']); break;
case 2: newFolder($_POST['basedir'], $_POST['newfolder']); break;
case 3: movePhotos($_POST['basedir'], $_POST['selected'], $_POST['moveto']); break;
}
echo '';
?>