Exemplo n.º 1
0
/**
 * 重命名文件
 * @param $oldName
 * @param $newName
 * @return string
 */
function renameFile($oldName, $newName)
{
    //检验文件名是否合法
    if (checkFilename($newName)) {
        //检测当前目录是否存在同名的文件
        $path = dirname($oldName);
        if (!file_exists($path . '/' . $newName)) {
            if (rename($oldName, $path . '/' . $newName)) {
                return "重命名成功";
            } else {
                return "重命名失败";
            }
        } else {
            return "同名的文件,请重新命名";
        }
    } else {
        return "非法的文件名";
    }
}
Exemplo n.º 2
0
/**
 * 重命名文件夹
 * @param string $oldname
 * @param string $newname
 * @return string
 */
function renameFolder($oldname, $newname)
{
    //检测文件夹名称的合法性
    if (checkFilename(basename($newname))) {
        //检测当前目录下是否存在同名文件夹名称
        if (!file_exists($newname)) {
            if (rename($oldname, $newname)) {
                $mes = "重命名成功";
            } else {
                $mes = "重命名失败";
            }
        } else {
            $mes = "存在同名文件夹";
        }
    } else {
        $mes = "非法文件夹名称";
    }
    return $mes;
}
Exemplo n.º 3
0
/**
 * 重命名文件
 * @param string $oldname
 * @param string $newname
 * @return string
 */
function renameFile($oldname, $newname)
{
    //	echo $oldname,$newname;
    //验证文件名是否合法
    if (checkFilename($newname)) {
        //检测当前目录下是否存在同名文件
        $path = dirname($oldname);
        if (!file_exists($path . "/" . $newname)) {
            //进行重命名
            if (rename($oldname, $path . "/" . $newname)) {
                return "重命名成功";
            } else {
                return "重命名失败";
            }
        } else {
            return "存在同名文件,请重新命名";
        }
    } else {
        return "非法文件名";
    }
}
Exemplo n.º 4
0
                    $smarty->assign('file', $_GET['file']);
                } else {
                    if ($_GET['file'] == 'resolutions.txt' && checkReadPerms($_GET['organ'])) {
                        $smarty->assign('text', readResolutions($_GET['organ']));
                        $smarty->assign('organ', $_GET['organ']);
                        $smarty->assign('file', $_GET['file']);
                    }
                }
            }
        }
    }
}
if (isset($_POST['text']) and isset($_GET['organ']) and isset($_GET['file'])) {
    //save changes
    if (checkOrgan($_GET['organ']) and checkWritePerms($_GET['organ'])) {
        if (checkFilename($_GET['file']) and checkLock($_SESSION['user'], $_GET['organ'], $_GET['file'])) {
            writeIntoFile($_POST['text'], $_GET['organ'], $_GET['file']);
            $smarty->assign('text', $_POST['text']);
            $smarty->assign('organ', $_GET['organ']);
            $smarty->assign('file', $_GET['file']);
            deleteLock($_GET['organ'], $_GET['file']);
        } else {
            if (checkAdminPerms($_GET['organ'])) {
                if ($_GET['file'] == "template") {
                    writeTemplate($_POST['text'], $_POST['organ']);
                    $smarty->assign('text', $_POST['text']);
                    $smarty->assign('organ', $_GET['organ']);
                    $smarty->assign('file', $_GET['file']);
                    deleteLock($_GET['organ'], $_GET['file']);
                } else {
                    if ($_GET['file'] == "email") {
Exemplo n.º 5
0
/**
 * 创建文件夹
 * @param $dirname
 * @return string
 */
function createFolder($dirname)
{
    if (checkFilename(basename($dirname))) {
        if (!file_exists($dirname)) {
            if (mkdir($dirname, 0777, true)) {
                $mes = '文件夹创建成功';
            } else {
                $mes = '文件夹创建失败';
            }
        } else {
            $mes = '文件夹已存在,请重命名后再创建';
        }
    } else {
        $mes = '非法文件夹名称';
    }
    return $mes;
}
Exemplo n.º 6
0
            $fullPath = checkFilename($newName, $_FILES['ax-files']['size'][$key]);
            if ($fullPath) {
                move_uploaded_file($_FILES['ax-files']['tmp_name'][$key], $fullPath);
                if (!empty($thumbWidth) || !empty($thumbHeight)) {
                    createThumbGD($fullPath, $thumbPath, $thumbPostfix, $thumbWidth, $thumbHeight, $thumbFormat);
                }
                echo json_encode(array('name' => basename($fullPath), 'size' => filesize($fullPath), 'status' => 'uploaded', 'info' => 'File uploaded'));
                //chmod("uploaded", 0775);
                system("/bin/chmod -R uploaded");
            }
        } else {
            echo json_encode(array('name' => basename($_FILES['ax-files']['name'][$key]), 'size' => $_FILES['ax-files']['size'][$key], 'status' => 'error', 'info' => $error));
        }
    }
} elseif (isset($_REQUEST['ax-file-name'])) {
    //check only the first peice
    $fullPath = $currByte != 0 ? $uploadPath . $fileName : checkFilename($fileName, $html5fsize);
    if ($fullPath) {
        $flag = $currByte == 0 ? 0 : FILE_APPEND;
        $receivedBytes = file_get_contents('php://input');
        //strange bug on very fast connections like localhost, some times cant write on file
        //TODO future version save parts on different files and then make join of parts
        while (@file_put_contents($fullPath, $receivedBytes, $flag) === false) {
            usleep(50);
        }
        if ($isLast == 'true') {
            createThumbGD($fullPath, $thumbPath, $thumbPostfix, $thumbWidth, $thumbHeight, $thumbFormat);
        }
        echo json_encode(array('name' => basename($fullPath), 'size' => $currByte, 'status' => 'uploaded', 'info' => 'File/chunk uploaded'));
    }
}
Exemplo n.º 7
0
/**
 * 创建文件夹
 * 2014-12-03 16:42:15
 * @param string $dirname
 * @return string
 */
function createFolder($dirname)
{
    //检查文件夹名称的合法性
    if (checkFilename(basename($dirname))) {
        //检查当前目录下是否存在同名文件夹名称
        if (!file_exists($dirname)) {
            if (mkdir($dirname, 0777, true)) {
                return "文件夹创建成功";
            } else {
                return "文件夹创建失败";
            }
        } else {
            return "存在同名文件夹";
        }
    } else {
        return "非法文件夹名称";
    }
}
Exemplo n.º 8
0
<?php

session_start();
require 'defines.php';
require 'lib.php';
header('Content-Type: text/xml');
echo '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
//check if a lock file exists
if (checkOrgan($_GET['organ'])) {
    if (checkFilename($_GET['file']) or $_GET['file'] == "template" or $_GET['file'] == "email" or $_GET['file'] == "resolutions.txt") {
        if (checkLock($_SESSION['user'], $_GET['organ'], $_GET['file'])) {
            createLock($_SESSION['user'], $_GET['organ'], $_GET['file']);
            echo '<response>Get lock file until ' . date('H-i', time() + 15 * 60) . ' </response>';
        } else {
            echo "<response>Another user is editing this file</response>";
        }
    }
}
Exemplo n.º 9
0
<?php

session_start();
require_once 'lib.php';
require_once 'defines.php';
if (isset($_GET['organ']) && isset($_GET['file'])) {
    if (checkOrgan($_GET['organ']) && checkReadPerms($_GET['organ']) && checkFilename($_GET['file'])) {
        $file = REPORTDIR . SUBUNPUBLISHED . $_GET['organ'] . "/" . $_GET['file'];
        pandocToPDF($file, $file . ".pdf");
        $text = file_get_contents(REPORTDIR . $_GET['organ'] . ".email");
        $text .= "\n Edit-Link: https://protokolle.asta.kit.edu/edit/" . $_GET['organ'] . "/" . $_GET['file'] . " \n";
        $text .= file_get_contents($file);
        echo rlyWriteEmail("*****@*****.**", "APVEL", $emailUN[$_GET['organ']], "Unveröffentlichtes Protokoll" . $_GET['file'] . " " . $_GET['organ'], $text, array($file . ".pdf", $file));
    }
}
Exemplo n.º 10
0
<?php

session_start();
// put full path to Smarty.class.php
require_once 'smartydef.php';
require 'defines.php';
require 'lib.php';
function remove_intern_tags($text)
{
    return preg_replace(INTERN_REGEX, "", $text);
}
$smarty->assign('this', 'publish.php');
if (isset($_GET['file']) && isset($_GET['organ'])) {
    if (checkOrgan($_GET['organ']) && checkFilename($_GET['file']) && checkAdminPerms($_GET['organ'])) {
        $organ = $_GET['organ'];
        $folder = REPORTDIR . SUBUNPUBLISHED . $organ . '/';
        $path = $folder . $_GET['file'];
        if (is_file($path)) {
            $text = readFromFile($organ, $_GET['file']);
            //remove [intern][/intern]
            $text = remove_intern_tags($text);
            if (isset($_GET['rly'])) {
                pandocToHTML($path, REPORTDIR . SUBPUBLISHED . $_GET['organ'] . "/" . $_GET['file'] . ".html");
                pandocToPDF($path, REPORTDIR . SUBPUBLISHED . $_GET['organ'] . "/" . $_GET['file'] . ".pdf");
                //resolution collection
                $conclusions = array();
                preg_match_all(";\\[beschluss\\](.*?)\\[/beschluss\\];s", $text, $conclusions);
                foreach ($conclusions[0] as $key => $con) {
                    $str = substr($con, 11, -12);
                    file_put_contents(REPORTDIR . SUBPUBLISHED . $_GET['organ'] . ".resolutions.txt", $_GET['file'] . ": " . $str . "\n", FILE_APPEND);
                }
Exemplo n.º 11
0
            if ($topCut) {
                // fotka se orezava pouze z vrchu
                imagickCrop($image, '50%', 0, $width, $height);
            } else {
                imagickCrop($image, '50%', '50%', $width, $height);
            }
        } else {
            $image->thumbnailImage($width, $height, $width && $height);
        }
    }
    $image->writeImage($newFilename);
}
// ------------------------ program -----------------------------------
$file = getFile();
if (isLocalFile($file)) {
    checkFilename($file);
    existsFile($file);
}
$height = getHeight();
$width = getWidth();
$exact = getExact();
$topCut = getTopCut();
if (isLocalFile($file)) {
    $newFilename = getResizedFilename($file, $height, $width, $exact, $topCut);
} else {
    $newFilename = getRemoteResizedFilename($file, $height, $width, $exact, $topCut);
}
if (!existsFile($newFilename, false)) {
    try {
        if (shouldSendOriginal($file, $height, $width, $exact || $topCut)) {
            sendFile($file);
Exemplo n.º 12
0
 function send_upload()
 {
     if ($this->session->userdata('status')) {
         $id_user = $this->uri->segment(4);
         error_reporting(E_ALL ^ E_NOTICE);
         //remove notice for json invalidation
         $uploadPath = $_REQUEST['ax-file-path'];
         if (is_dir($uploadPath)) {
             //echo json_encode(array('path' => $uploadPath, 'MSG' => "Path no encontado"));
             //die();
         }
         $fileName = $_REQUEST['ax-file-name'];
         $currByte = $_REQUEST['ax-start-byte'];
         $maxFileSize = $_REQUEST['ax-maxFileSize'];
         $html5fsize = $_REQUEST['ax-fileSize'];
         $isLast = $_REQUEST['isLast'];
         //if set generates thumbs only on images type files
         $thumbHeight = $_REQUEST['ax-thumbHeight'];
         $thumbWidth = $_REQUEST['ax-thumbWidth'];
         $thumbPostfix = $_REQUEST['ax-thumbPostfix'];
         $thumbPath = $_REQUEST['ax-thumbPath'];
         $thumbFormat = $_REQUEST['ax-thumbFormat'];
         $allowExt = empty($_REQUEST['ax-allow-ext']) ? array() : explode('|', $_REQUEST['ax-allow-ext']);
         $uploadPath .= !in_array(substr($uploadPath, -1), array('\\', '/')) ? DIRECTORY_SEPARATOR : '';
         //normalize path
         if (!file_exists($uploadPath) && !empty($uploadPath)) {
             mkdir($uploadPath, 0777, true);
         }
         if (!file_exists($thumbPath) && !empty($thumbPath)) {
             mkdir($thumbPath, 0777, true);
         }
         //with gd library
         function createThumbGD($filepath, $thumbPath, $postfix, $maxwidth, $maxheight, $format = 'jpg', $quality = 75)
         {
             if ($maxwidth <= 0 && $maxheight <= 0) {
                 return 'No valid width and height given';
             }
             $gd_formats = array('jpg', 'jpeg', 'png', 'gif');
             //web formats
             $file_name = pathinfo($filepath);
             if (empty($format)) {
                 $format = $file_name['extension'];
             }
             if (!in_array(strtolower($file_name['extension']), $gd_formats)) {
                 return false;
             }
             $thumb_name = $file_name['filename'] . $postfix . '.' . $format;
             if (empty($thumbPath)) {
                 $thumbPath = $file_name['dirname'];
             }
             $thumbPath .= !in_array(substr($thumbPath, -1), array('\\', '/')) ? DIRECTORY_SEPARATOR : '';
             //normalize path
             // Get new dimensions
             list($width_orig, $height_orig) = getimagesize($filepath);
             if ($width_orig > 0 && $height_orig > 0) {
                 $ratioX = $maxwidth / $width_orig;
                 $ratioY = $maxheight / $height_orig;
                 $ratio = min($ratioX, $ratioY);
                 $ratio = $ratio == 0 ? max($ratioX, $ratioY) : $ratio;
                 $newW = $width_orig * $ratio;
                 $newH = $height_orig * $ratio;
                 // Resample
                 $thumb = imagecreatetruecolor($newW, $newH);
                 $image = imagecreatefromstring(file_get_contents($filepath));
                 imagecopyresampled($thumb, $image, 0, 0, 0, 0, $newW, $newH, $width_orig, $height_orig);
                 // Output
                 switch (strtolower($format)) {
                     case 'png':
                         imagepng($thumb, $thumbPath . $thumb_name, 9);
                         break;
                     case 'gif':
                         imagegif($thumb, $thumbPath . $thumb_name);
                         break;
                     default:
                         imagejpeg($thumb, $thumbPath . $thumb_name, $quality);
                         break;
                 }
                 imagedestroy($image);
                 imagedestroy($thumb);
             } else {
                 return false;
             }
         }
         //for image magick
         function createThumbIM($filepath, $thumbPath, $postfix, $maxwidth, $maxheight, $format)
         {
             $file_name = pathinfo($filepath);
             $thumb_name = $file_name['filename'] . $postfix . '.' . $format;
             if (empty($thumbPath)) {
                 $thumbPath = $file_name['dirname'];
             }
             $thumbPath .= !in_array(substr($thumbPath, -1), array('\\', '/')) ? DIRECTORY_SEPARATOR : '';
             //normalize path
             $image = new Imagick($filepath);
             $image->thumbnailImage($maxwidth, $maxheight);
             $images->writeImages($thumbPath . $thumb_name);
         }
         function checkFilename($fileName, $size, $newName = '')
         {
             global $allowExt, $uploadPath, $maxFileSize;
             //------------------max file size check from js
             $maxsize_regex = preg_match("/^(?'size'[\\d]+)(?'rang'[a-z]{0,1})\$/i", $maxFileSize, $match);
             $maxSize = 4 * 1024 * 1024;
             //default 4 M
             if ($maxsize_regex && is_numeric($match['size'])) {
                 switch (strtoupper($match['rang'])) {
                     case 'K':
                         $maxSize = $match[1] * 1024;
                         break;
                     case 'M':
                         $maxSize = $match[1] * 1024 * 1024;
                         break;
                     case 'G':
                         $maxSize = $match[1] * 1024 * 1024 * 1024;
                         break;
                     case 'T':
                         $maxSize = $match[1] * 1024 * 1024 * 1024 * 1024;
                         break;
                     default:
                         $maxSize = $match[1];
                         //default 4 M
                 }
             }
             if (!empty($maxFileSize) && $size > $maxSize) {
                 echo json_encode(array('name' => $fileName, 'size' => $size, 'status' => 'error', 'info' => 'File size not allowed.'));
                 return false;
             }
             //-----------------End max file size check
             //comment if not using windows web server
             $windowsReserved = array('CON', 'PRN', 'AUX', 'NUL', 'COM1', 'COM2', 'COM3', 'COM4', 'COM5', 'COM6', 'COM7', 'COM8', 'COM9', 'LPT1', 'LPT2', 'LPT3', 'LPT4', 'LPT5', 'LPT6', 'LPT7', 'LPT8', 'LPT9');
             $badWinChars = array_merge(array_map('chr', range(0, 31)), array("<", ">", ":", '"', "/", "\\", "|", "?", "*"));
             $fileName = str_replace($badWinChars, '', $fileName);
             $fileInfo = pathinfo($fileName);
             $fileExt = $fileInfo['extension'];
             $fileBase = $fileInfo['filename'];
             //check if legal windows file name
             if (in_array($fileName, $windowsReserved)) {
                 echo json_encode(array('name' => $fileName, 'size' => 0, 'status' => 'error', 'info' => 'File name not allowed. Windows reserverd.'));
                 return false;
             }
             //check if is allowed extension
             if (!in_array($fileExt, $allowExt) && count($allowExt)) {
                 echo json_encode(array('name' => $fileName, 'size' => 0, 'status' => 'error', 'info' => "Extension [{$fileExt}] not allowed."));
                 return false;
             }
             $fullPath = $uploadPath . $fileName;
             $c = 0;
             while (file_exists($fullPath)) {
                 $c++;
                 $fileName = $fileBase . "({$c})." . $fileExt;
                 $fullPath = $uploadPath . $fileName;
             }
             return $fullPath;
         }
         if (isset($_FILES['ax-files'])) {
             //for eahc theorically runs only 1 time, since i upload i file per time
             foreach ($_FILES['ax-files']['error'] as $key => $error) {
                 if ($error == UPLOAD_ERR_OK) {
                     $newName = !empty($fileName) ? $fileName : $_FILES['ax-files']['name'][$key];
                     $fullPath = checkFilename($newName, $_FILES['ax-files']['size'][$key]);
                     if ($fullPath) {
                         move_uploaded_file($_FILES['ax-files']['tmp_name'][$key], $fullPath);
                         if (!empty($thumbWidth) || !empty($thumbHeight)) {
                             createThumbGD($fullPath, $thumbPath, $thumbPostfix, $thumbWidth, $thumbHeight, $thumbFormat);
                         }
                         echo json_encode(array('name' => basename($fullPath), 'size' => filesize($fullPath), 'status' => 'uploaded', 'info' => 'File uploaded'));
                     }
                 } else {
                     echo json_encode(array('name' => basename($_FILES['ax-files']['name'][$key]), 'size' => $_FILES['ax-files']['size'][$key], 'status' => 'error', 'info' => $error));
                 }
             }
         } elseif (isset($_REQUEST['ax-file-name'])) {
             //check only the first peice
             $fullPath = $currByte != 0 ? $uploadPath . $fileName : checkFilename($fileName, $html5fsize);
             if ($fullPath) {
                 $flag = $currByte == 0 ? 0 : FILE_APPEND;
                 $receivedBytes = file_get_contents('php://input');
                 //strange bug on very fast connections like localhost, some times cant write on file
                 //TODO future version save parts on different files and then make join of parts
                 while (@file_put_contents($fullPath, $receivedBytes, $flag) === false) {
                     usleep(50);
                 }
                 if ($isLast == 'true') {
                     createThumbGD($fullPath, $thumbPath, $thumbPostfix, $thumbWidth, $thumbHeight, $thumbFormat);
                 }
                 redim_imagen("./upload/" . $fullPath, "./upload/thumb_" . $fullPath, 240, 240, 1);
                 $query = array('id' => '', 'author' => $id_user, 'fecha' => time(), 'path' => $fullPath, 'thumb' => 'thumb_' . $fullPath, 'active' => '0');
                 $this->db->insert('galeria', $query);
                 activity_add($this->session->userdata('id'), '3');
                 echo json_encode(array('name' => basename($fullPath), 'size' => $currByte, 'status' => 'uploaded', 'info' => 'File/chunk uploaded'));
             }
         }
     } else {
         redirect('perfil');
     }
 }