Ejemplo n.º 1
0
function FileUpload($resourceType, $currentFolder, $sCommand)
{
    if (!isset($_FILES)) {
        global $_FILES;
    }
    $sErrorNumber = '0';
    $sFileName = '';
    if (isset($_FILES['NewFile']) && !is_null($_FILES['NewFile']['tmp_name'])) {
        global $Config;
        $oFile = $_FILES['NewFile'];
        // Map the virtual path to the local server path.
        $sServerDir = ServerMapFolder($resourceType, $currentFolder, $sCommand);
        // Get the uploaded file name.
        $sFileName = time() . "." . strtolower(array_pop(explode(".", $oFile['name'])));
        $sFileName = SanitizeFileName($sFileName);
        $sOriginalFileName = $sFileName;
        // Get the extension.
        $sExtension = substr($sFileName, strrpos($sFileName, '.') + 1);
        $sExtension = strtolower($sExtension);
        if (isset($Config['SecureImageUploads'])) {
            if (($isImageValid = IsImageValid($oFile['tmp_name'], $sExtension)) === false) {
                $sErrorNumber = '202';
            }
        }
        if (isset($Config['HtmlExtensions'])) {
            if (!IsHtmlExtension($sExtension, $Config['HtmlExtensions']) && ($detectHtml = DetectHtml($oFile['tmp_name'])) === true) {
                $sErrorNumber = '202';
            }
        }
        // Check if it is an allowed extension.
        if (!$sErrorNumber && IsAllowedExt($sExtension, $resourceType)) {
            $iCounter = 0;
            while (true) {
                $sFilePath = $sServerDir . $sFileName;
                if (is_file($sFilePath)) {
                    $iCounter++;
                    $sFileName = RemoveExtension($sOriginalFileName) . '(' . $iCounter . ').' . $sExtension;
                    $sErrorNumber = '201';
                } else {
                    move_uploaded_file($oFile['tmp_name'], $sFilePath);
                    if (is_file($sFilePath)) {
                        if (isset($Config['ChmodOnUpload']) && !$Config['ChmodOnUpload']) {
                            break;
                        }
                        $permissions = 0777;
                        if (isset($Config['ChmodOnUpload']) && $Config['ChmodOnUpload']) {
                            $permissions = $Config['ChmodOnUpload'];
                        }
                        $oldumask = umask(0);
                        chmod($sFilePath, $permissions);
                        umask($oldumask);
                    }
                    break;
                }
            }
            if ($_POST['C1'] == "ON") {
                $watermark = 1;
                //是否附加水印(1为加水印,其他为不加水印);
            } else {
                $watermark = 2;
            }
            if ($_POST['R1'] == "V1") {
                $watertype = 1;
                //水印类型(1为文字,2为图片)
            } else {
                $watertype = 2;
            }
            if ($_POST['T1'] == "") {
                $waterstring = 'http://www.bb580.com.cn';
                //水印字符串
            } else {
                $waterstring = $_POST['T1'];
            }
            $waterimg = "logo.png";
            //水印图片
            if ($watermark == 1) {
                $image_size = getimagesize($sFilePath);
                $awidth = $image_size[0];
                $aheight = $image_size[1];
                $iinfo = getimagesize($sFilePath, $iinfo);
                $nimage = imagecreatetruecolor($image_size[0], $image_size[1]);
                $white = imagecolorallocate($nimage, 255, 255, 255);
                $black = imagecolorallocate($nimage, 0, 0, 0);
                $red = imagecolorallocate($nimage, 255, 0, 0);
                imagefill($nimage, 0, 0, $white);
                switch ($iinfo[2]) {
                    case 1:
                        $simage = imagecreatefromgif($sFilePath);
                        break;
                    case 2:
                        $simage = imagecreatefromjpeg($sFilePath);
                        break;
                    case 3:
                        $simage = imagecreatefrompng($sFilePath);
                        break;
                    case 6:
                        $simage = imagecreatefromwbmp($sFilePath);
                        break;
                    default:
                        die("不支持的文件类型");
                        exit;
                }
                imagecopy($nimage, $simage, 0, 0, 0, 0, $image_size[0], $image_size[1]);
                switch ($watertype) {
                    case 1:
                        //加水印字符串
                        imagestring($nimage, 2, 3, $image_size[1] - 15, $waterstring, $black);
                        break;
                    case 2:
                        //加水印图片
                        $simage1 = imagecreatefrompng($waterimg);
                        imagecopy($nimage, $simage1, $awidth - 151, $aheight - 50, 0, 0, 151, 50);
                        imagedestroy($simage1);
                        break;
                }
                switch ($iinfo[2]) {
                    case 1:
                        imagegif($nimage, $sFilePath);
                        imagejpeg($nimage, $sFilePath);
                        break;
                    case 2:
                        imagejpeg($nimage, $sFilePath);
                        break;
                    case 3:
                        imagepng($nimage, $sFilePath);
                        break;
                    case 6:
                        imagewbmp($nimage, $sFilePath);
                        imagejpeg($nimage, $sFilePath);
                        break;
                }
                //覆盖原上传文件
                imagedestroy($nimage);
                imagedestroy($simage);
            }
            if (file_exists($sFilePath)) {
                //previous checks failed, try once again
                if (isset($isImageValid) && $isImageValid === -1 && IsImageValid($sFilePath, $sExtension) === false) {
                    @unlink($sFilePath);
                    $sErrorNumber = '202';
                } else {
                    if (isset($detectHtml) && $detectHtml === -1 && DetectHtml($sFilePath) === true) {
                        @unlink($sFilePath);
                        $sErrorNumber = '202';
                    }
                }
            }
        } else {
            $sErrorNumber = '202';
        }
    } else {
        $sErrorNumber = '202';
    }
    $sFileUrl = CombinePaths(GetResourceTypePath($resourceType, $sCommand), $currentFolder);
    $sFileUrl = CombinePaths($sFileUrl, $sFileName);
    SendUploadResults($sErrorNumber, $sFileUrl, $sFileName);
    exit;
}
Ejemplo n.º 2
0
function FileUpload($resourceType, $currentFolder, $sCommand)
{
    global $cfg;
    global $db;
    $tbl_attachment = $cfg['tbl_attachment'];
    if (!isset($_FILES)) {
        global $_FILES;
    }
    //print_r($_FILES['type']);
    $sErrorNumber = '0';
    $sFileName = '';
    if (!isset($_FILES['NewFile'])) {
        $temp = $_FILES['file'];
        $_FILES['NewFile'] = $temp;
        $flag = 0;
    } else {
        $flag = 1;
    }
    if (isset($_FILES['NewFile']) && !is_null($_FILES['NewFile']['tmp_name'])) {
        global $Config;
        $oFile = $_FILES['NewFile'];
        $mime_type = $oFile['type'];
        // Map the virtual path to the local server path.
        $sServerDir = ServerMapFolder($resourceType, $currentFolder, $sCommand);
        // Get the uploaded file name.
        $sFileName = $oFile['name'];
        $sFileName = SanitizeFileName($sFileName);
        $sOriginalFileName = $sFileName;
        // Get the extension.
        $sExtension = substr($sFileName, strrpos($sFileName, '.') + 1);
        $sExtension = strtolower($sExtension);
        $sFileName = "flow_" . str_replace(array("0.", " "), array("", "_"), microtime()) . "." . $sExtension;
        if (isset($Config['SecureImageUploads'])) {
            if (($isImageValid = IsImageValid($oFile['tmp_name'], $sExtension)) === false) {
                $sErrorNumber = '202';
            }
        }
        if (isset($Config['HtmlExtensions'])) {
            if (!IsHtmlExtension($sExtension, $Config['HtmlExtensions']) && ($detectHtml = DetectHtml($oFile['tmp_name'])) === true) {
                $sErrorNumber = '202';
            }
        }
        // Check if it is an allowed extension.
        if (!$sErrorNumber && IsAllowedExt($sExtension, $resourceType)) {
            $iCounter = 0;
            while (true) {
                $sFilePath = $sServerDir . $sFileName;
                if (is_file($sFilePath)) {
                    $iCounter++;
                    $sFileName = RemoveExtension($sOriginalFileName) . '(' . $iCounter . ').' . $sExtension;
                    $sErrorNumber = '201';
                } else {
                    move_uploaded_file($oFile['tmp_name'], $sFilePath);
                    if (is_file($sFilePath)) {
                        if (isset($Config['ChmodOnUpload']) && !$Config['ChmodOnUpload']) {
                            break;
                        }
                        $permissions = 0777;
                        if (isset($Config['ChmodOnUpload']) && $Config['ChmodOnUpload']) {
                            $permissions = $Config['ChmodOnUpload'];
                        }
                        $oldumask = umask(0);
                        chmod($sFilePath, $permissions);
                        umask($oldumask);
                    }
                    break;
                }
            }
            if (file_exists($sFilePath)) {
                //previous checks failed, try once again
                if (isset($isImageValid) && $isImageValid === -1 && IsImageValid($sFilePath, $sExtension) === false) {
                    @unlink($sFilePath);
                    $sErrorNumber = '202';
                } else {
                    if (isset($detectHtml) && $detectHtml === -1 && DetectHtml($sFilePath) === true) {
                        @unlink($sFilePath);
                        $sErrorNumber = '202';
                    }
                }
            }
        } else {
            $sErrorNumber = '202';
        }
    } else {
        $sErrorNumber = '202';
    }
    if (isset($_GET['object_id'])) {
        $object_id = intval($_GET['object_id']);
    } else {
        if (isset($_POST['object_id'])) {
            $object_id = intval($_POST['object_id']);
        } else {
            global $object_id;
        }
    }
    if (isset($_GET['class_id'])) {
        $class_id = intval($_GET['class_id']);
    } else {
        if (isset($_POST['class_id'])) {
            $class_id = intval($_POST['class_id']);
        } else {
            $class_id = 1;
        }
    }
    if (!$sErrorNumber && file_exists($sFilePath)) {
        $sFileUrl = CombinePaths(GetResourceTypePath($resourceType, $sCommand), $currentFolder);
        $sFileUrl = CombinePaths($sFileUrl, $sFileName);
        $sql = "insert into {$tbl_attachment} (catalog_id,object_id,filename,formername,ext,mime,mime_type,dt) values ('{$class_id}','{$object_id}','{$sFileName}','{$sOriginalFileName}','{$sExtension}','{$resourceType}','{$mime_type}','" . date("Y-m-d H:i:s", time() + 8 * 3600) . "')";
        @$db->Execute($sql);
        if ($resourceType == "File") {
            $cmd = "download";
        } else {
            $cmd = "preview";
        }
        $sFileUrl = $cfg['flow_basedir'] . "file.php?cmd=" . $cmd . "&id=" . $db->Insert_ID();
    }
    if ($flag == "1") {
        SendUploadResults($sErrorNumber, $sFileUrl, $sFileName);
    } else {
        echo "\r\n\t\t\t<script language='JavaScript'>\r\n\t\t\t\t<!--\r\n\t\t\t\t\twindow.location.href='" . $cfg['flow_basedir'] . "flowcms/filebrowser.php?Type={$resourceType}&class_id={$class_id}&object_id={$object_id}';\r\n\t\t\t\t//-->\r\n\t\t\t</script>\r\n\t\t";
    }
    exit;
}
Ejemplo n.º 3
0
$arDenied = $Config['DeniedExtensions'][$sType];
// Check if it is an allowed extension.
if (count($arAllowed) > 0 && !in_array($sExtension, $arAllowed) || count($arDenied) > 0 && in_array($sExtension, $arDenied)) {
    SendResults('202');
}
$sErrorNumber = '0';
$sFileUrl = '';
// Initializes the counter used to rename the file, if another one with the same name already exists.
$iCounter = 0;
// The the target directory.
$sServerDir = GetRootPath() . $Config["UserFilesPath"];
while (true) {
    // Compose the file path.
    $sFilePath = $sServerDir . $sFileName;
    // If a file with that name already exists.
    if (is_file($sFilePath)) {
        $iCounter++;
        $sFileName = RemoveExtension($sOriginalFileName) . '(' . $iCounter . ').' . $sExtension;
        $sErrorNumber = '201';
    } else {
        move_uploaded_file($oFile['tmp_name'], $sFilePath);
        if (is_file($sFilePath)) {
            $oldumask = umask(0);
            chmod($sFilePath, 0777);
            umask($oldumask);
        }
        $sFileUrl = $Config["UserFilesPath"] . $sFileName;
        break;
    }
}
SendResults($sErrorNumber, $sFileUrl, $sFileName);
Ejemplo n.º 4
0
function FileUpload($resourceType, $currentFolder)
{
    $sErrorNumber = '0';
    $sFileName = '';
    if (isset($_FILES['NewFile']) && !is_null($_FILES['NewFile']['tmp_name'])) {
        global $Config;
        $oFile = $_FILES['NewFile'];
        // Map the virtual path to the local server path.
        $sServerDir = ServerMapFolder($resourceType, $currentFolder);
        // Get the uploaded file name.
        $sFileName = $oFile['name'];
        // Replace dots in the name with underscores (only one dot can be there... security issue).
        if ($Config['ForceSingleExtension']) {
            $sFileName = preg_replace('/\\.(?![^.]*$)/', '_', $sFileName);
        }
        $sOriginalFileName = $sFileName;
        // Get the extension.
        $sExtension = substr($sFileName, strrpos($sFileName, '.') + 1);
        $sExtension = strtolower($sExtension);
        // Selected image width
        $iWidth = isset($_POST['WidthOpt']) && $_POST['WidthOpt'] ? intval($_POST['WidthOpt']) : (isset($_POST['Width']) && $_POST['Width'] ? intval($_POST['Width']) : 0);
        $arAllowed = $Config['AllowedExtensions'][$resourceType];
        $arDenied = $Config['DeniedExtensions'][$resourceType];
        if ((count($arAllowed) == 0 || in_array($sExtension, $arAllowed)) && (count($arDenied) == 0 || !in_array($sExtension, $arDenied))) {
            $iCounter = 0;
            while (true) {
                $sFilePath = $sServerDir . $sFileName;
                if (is_file($sFilePath)) {
                    $iCounter++;
                    $sFileName = RemoveExtension($sOriginalFileName) . '(' . $iCounter . ').' . $sExtension;
                    $sErrorNumber = '201';
                } else {
                    if ($iWidth) {
                        $oImg = new Image($oFile);
                        $oImg->resize($iWidth);
                        $oImg->save($sFilePath);
                    } else {
                        move_uploaded_file($oFile['tmp_name'], $sFilePath);
                    }
                    if (is_file($sFilePath)) {
                        $oldumask = umask(0);
                        chmod($sFilePath, 0777);
                        umask($oldumask);
                    }
                    break;
                }
            }
        } else {
            $sErrorNumber = '202';
        }
    } else {
        $sErrorNumber = '202';
    }
    echo '<script type="text/javascript">';
    echo 'window.parent.frames["frmUpload"].OnUploadCompleted(' . $sErrorNumber . ',"' . str_replace('"', '\\"', $sFileName) . '") ;';
    echo '</script>';
    exit;
}
Ejemplo n.º 5
0
function FileUpload($resourceType, $currentFolder, $sCommand)
{
    if (!isset($_FILES)) {
        global $_FILES;
    }
    $sErrorNumber = '0';
    $sFileName = '';
    if (isset($_FILES['NewFile']) && !is_null($_FILES['NewFile']['tmp_name'])) {
        global $Config;
        $oFile = $_FILES['NewFile'];
        // No POST errors in uploading?
        if ($oFile['error'] !== UPLOAD_ERR_OK) {
            $sErrorNumber = '1';
            switch ($oFile['error']) {
                case UPLOAD_ERR_INI_SIZE:
                    $err_msg = 'The uploaded file exceeds the upload_max_filesize directive in php.ini';
                    break;
                case UPLOAD_ERR_FORM_SIZE:
                    $err_msg = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form';
                    break;
                case UPLOAD_ERR_PARTIAL:
                    $err_msg = 'The uploaded file was only partially uploaded';
                    break;
                case UPLOAD_ERR_NO_FILE:
                    $err_msg = 'No file was uploaded';
                    break;
                case UPLOAD_ERR_NO_TMP_DIR:
                    $err_msg = 'Missing a temporary folder';
                    break;
                case UPLOAD_ERR_CANT_WRITE:
                    $err_msg = 'Failed to write file to disk';
                    break;
                case UPLOAD_ERR_EXTENSION:
                    $err_msg = 'File upload stopped by extension';
                    break;
                default:
                    $err_msg = 'Unknown upload error';
            }
            SendUploadResults($sErrorNumber, '', '', $err_msg);
            exit;
        }
        // Is of proper size?
        if ($Config['k_max_upload_size']) {
            $max = $Config['k_max_upload_size'] * 1024 * 1024;
            if ($oFile['size'] > $Config['k_max_upload_size'] * 1024 * 1024) {
                $sErrorNumber = '1';
                $err_msg = 'File too large. Cannot be over ' . $Config['k_max_upload_size'] . ' MB in size.';
                SendUploadResults($sErrorNumber, '', '', $err_msg);
                exit;
            }
        }
        // Map the virtual path to the local server path.
        $sServerDir = ServerMapFolder($resourceType, $currentFolder, $sCommand);
        // Get the uploaded file name.
        $sFileName = $oFile['name'];
        $sFileName = SanitizeFileName($sFileName);
        $sOriginalFileName = $sFileName;
        // Get the extension.
        $sExtension = '';
        if (strrpos($sFileName, '.') !== false) {
            $sExtension = substr($sFileName, strrpos($sFileName, '.') + 1);
            $sExtension = strtolower($sExtension);
        }
        if ($sExtension != '') {
            if (isset($Config['SecureImageUploads'])) {
                if (($isImageValid = IsImageValid($oFile['tmp_name'], $sExtension)) === false) {
                    $sErrorNumber = '202';
                }
            }
            if (isset($Config['HtmlExtensions'])) {
                if (!IsHtmlExtension($sExtension, $Config['HtmlExtensions']) && ($detectHtml = DetectHtml($oFile['tmp_name'])) === true) {
                    $sErrorNumber = '202';
                }
            }
        }
        // Check if it is an allowed extension.
        if ($sExtension != '' && !$sErrorNumber && IsAllowedExt($sExtension, $resourceType)) {
            $iCounter = 0;
            while (true) {
                $sFilePath = $sServerDir . $sFileName;
                if (is_file($sFilePath)) {
                    $iCounter++;
                    $sFileName = RemoveExtension($sOriginalFileName) . '-' . $iCounter . '.' . $sExtension;
                    $sErrorNumber = '201';
                } else {
                    if (defined('K_GALLERY_UPLOAD')) {
                        $res = rename($oFile['tmp_name'], $sFilePath);
                    } else {
                        $res = move_uploaded_file($oFile['tmp_name'], $sFilePath);
                    }
                    if ($res === FALSE) {
                        $sErrorNumber = '203';
                        break;
                    }
                    if (is_file($sFilePath)) {
                        if (isset($Config['ChmodOnUpload']) && !$Config['ChmodOnUpload']) {
                            break;
                        }
                        $permissions = 0777;
                        if (isset($Config['ChmodOnUpload']) && $Config['ChmodOnUpload']) {
                            $permissions = $Config['ChmodOnUpload'];
                        }
                        $oldumask = umask(0);
                        chmod($sFilePath, $permissions);
                        umask($oldumask);
                    }
                    break;
                }
            }
            if (file_exists($sFilePath)) {
                //previous checks failed, try once again
                if (isset($isImageValid) && $isImageValid === -1 && IsImageValid($sFilePath, $sExtension) === false) {
                    @unlink($sFilePath);
                    $sErrorNumber = '202';
                } else {
                    if (isset($detectHtml) && $detectHtml === -1 && DetectHtml($sFilePath) === true) {
                        @unlink($sFilePath);
                        $sErrorNumber = '202';
                    }
                }
            }
        } else {
            $sErrorNumber = '202';
        }
    } else {
        $sErrorNumber = '202';
    }
    $sFileUrl = CombinePaths(GetResourceTypePath($resourceType, $sCommand), $currentFolder);
    $sFileUrl = CombinePaths($sFileUrl, $sFileName);
    $res = SendUploadResults($sErrorNumber, $sFileUrl, $sFileName);
    if (defined('K_GALLERY_UPLOAD')) {
        return $res;
    }
    exit;
}
Ejemplo n.º 6
0
if (is_dir($rrdpath)) {
    $db = new ossim_db();
    $conn = $db->connect();
    if ($gestordir = opendir($rrdpath)) {
        $i = 0;
        $nrrds = 0;
        $rrds = array();
        while (($rrdfile = readdir($gestordir)) !== false) {
            if (strcmp($rrdfile, "..") == 0 || strcmp($rrdfile, ".") == 0) {
                continue;
            }
            $file_date = @filemtime($rrdpath . DIRECTORY_SEPARATOR . $rrdfile);
            // Get files list modified after start date
            if (isset($start) && $file_date !== false && $file_date > $start) {
                // Draw graph
                $id = RemoveExtension($rrdfile, ".rrd");
                $entity_type = Session::get_entity_type($conn, $id);
                if ($entity_type == 'context') {
                    // Ignore engines and Logical entities
                    ?>
						<tr>
							<td style='padding-bottom:10px' align='center'>
							<center>
								<h4><i><?php 
                    echo Session::get_entity_name($conn, $id);
                    ?>
</i></h4>
								<img src="<?php 
                    echo "../report/graphs/draw_rrd.php?id={$id}&what=eps&start={$start}&end={$end}&type=eps";
                    ?>
" border='0'/>
Ejemplo n.º 7
0
     //Do no proccessing, set some basic db values tho..
     //$upload_folder = "".$settings['siteurl']."infusions/the_kroax/uploads/movies/";
     $filename = $upload_name;
     $photo_dest = "";
     $photo_thumb1 = "";
 } else {
     function RemoveExtension($strName)
     {
         $ext = strrchr($strName, '.');
         if ($ext !== false) {
             $strName = substr($strName, 0, -strlen($ext));
         }
         return $strName;
     }
     $out = "{$filename}";
     $out = RemoveExtension($out);
     $saveflvpath = INFUSIONS . "the_kroax/uploads/movies/";
     $saveflv = "{$out}.flv";
     $saveimgpath = INFUSIONS . "the_kroax/uploads/thumbs/";
     //$saveimgpath = "../uploads/thumbs/";
     $saveimg = "{$out}.jpg";
     $ffmpeg = "C:/ffmpeg/ffmpeg";
     echo "<br>";
     //Lets not proccess flv files..
     if ($type == "flv") {
     } else {
         echo "<fieldset><legend>" . $locale['KROAX426'] . "</legend>";
         //High quality 18 mb > 16 mb no quality differance $command = $ffmpeg."  -v 0 -i $saveflvpath$filename -s 320x240 -b 500k -ar 44100 $saveflvpath$saveflv";
         //not to high quality shrunk 18 mb to 6 mb..$command = $ffmpeg."  -v 0 -i $saveflvpath$filename -s 320x240 -ar 44100 $saveflvpath$saveflv";
         $command = "" . $ffmpeg . "  -v 0 -i " . $saveflvpath . "" . $filename . " -ar 44100 " . $saveflvpath . "" . $saveflv . "";
         $output = exec($command . " 2>&1");
Ejemplo n.º 8
0
function FileUpload($resourceType, $currentFolder, $sCommand, $CKEcallback = '')
{
    if (!isset($_FILES)) {
        global $_FILES;
    }
    $sErrorNumber = '0';
    $sFileName = '';
    $customError = '';
    //PATCH to detect a quick file upload.
    if (isset($_FILES['NewFile']) && !is_null($_FILES['NewFile']['tmp_name']) || isset($_FILES['upload']) && !is_null($_FILES['upload']['tmp_name'])) {
        global $config;
        //PATCH to detect a quick file upload.
        $oFile = isset($_FILES['NewFile']) ? $_FILES['NewFile'] : $_FILES['upload'];
        // Map the virtual path to the local server path.
        $sServerDir = ServerMapFolder($resourceType, $currentFolder, $sCommand);
        // Get the uploaded file name.
        $sFileName = $oFile['name'];
        $sFileName = SanitizeFileName($sFileName);
        $sOriginalFileName = $sFileName;
        // Get the extension.
        $sExtension = substr($sFileName, strrpos($sFileName, '.') + 1);
        $sExtension = strtolower($sExtension);
        if (isset($config['SecureImageUploads'])) {
            if (($isImageValid = IsImageValid($oFile['tmp_name'], $sExtension)) == false) {
                $sErrorNumber = '202';
            }
        }
        if (isset($config['HtmlExtensions'])) {
            if (!IsHtmlExtension($sExtension, $config['HtmlExtensions']) && ($detectHtml = DetectHtml($oFile['tmp_name'])) == true) {
                $sErrorNumber = '202';
            }
        }
        if ($oFile["size"] / 1024 > $config['MaxImageSize']) {
            $sErrorNumber = '1';
            $customError = "Can't upload max size " . $config['MaxImageSize'] . "KB";
        }
        // Check if it is an allowed extension.
        if (!$sErrorNumber && IsAllowedExt($sExtension, $resourceType)) {
            if ($config['UploadOrginalFilename']) {
                // อัปโหลดใช้ชื่อเดิม
                $iCounter = 0;
                while (true) {
                    $sFilePath = $sServerDir . $sFileName;
                    if (is_file($sFilePath)) {
                        $iCounter++;
                        $sFileName = RemoveExtension($sOriginalFileName) . '(' . $iCounter . ').' . $sExtension;
                        $sErrorNumber = '201';
                    } else {
                        move_uploaded_file($oFile['tmp_name'], $sFilePath);
                        if (is_file($sFilePath)) {
                            if (isset($config['ChmodOnUpload']) && !$config['ChmodOnUpload']) {
                                break;
                            }
                            $permissions = 0777;
                            if (isset($config['ChmodOnUpload']) && $config['ChmodOnUpload']) {
                                $permissions = $config['ChmodOnUpload'];
                            }
                            $oldumask = umask(0);
                            chmod($sFilePath, $permissions);
                            umask($oldumask);
                        }
                        break;
                    }
                }
            } else {
                // อัปโหลดโดยใช้เวลาเป็นชื่อไฟล์
                $iCounter = date('U');
                while (true) {
                    $sFileName = "{$iCounter}.{$sExtension}";
                    $sFilePath = $sServerDir . $sFileName;
                    if (is_file($sFilePath)) {
                        $iCounter++;
                        $sFileName = "{$iCounter}.{$sExtension}";
                    } else {
                        move_uploaded_file($oFile['tmp_name'], $sFilePath);
                        if (is_file($sFilePath)) {
                            if (isset($config['ChmodOnUpload']) && !$config['ChmodOnUpload']) {
                                break;
                            }
                            $permissions = 0777;
                            if (isset($config['ChmodOnUpload']) && $config['ChmodOnUpload']) {
                                $permissions = $config['ChmodOnUpload'];
                            }
                            $oldumask = umask(0);
                            chmod($sFilePath, $permissions);
                            umask($oldumask);
                        }
                        break;
                    }
                }
            }
            if (file_exists($sFilePath)) {
                //previous checks failed, try once again
                if (isset($isImageValid) && $isImageValid == -1 && IsImageValid($sFilePath, $sExtension) == false) {
                    @unlink($sFilePath);
                    $sErrorNumber = '202';
                } elseif (isset($detectHtml) && $detectHtml == -1 && DetectHtml($sFilePath) == true) {
                    @unlink($sFilePath);
                    $sErrorNumber = '202';
                }
            }
        } else {
            $sErrorNumber = $sErrorNumber;
        }
    } else {
        $sErrorNumber = '202';
    }
    $sFileUrl = CombinePaths(GetResourceTypePath($resourceType, $sCommand), $currentFolder);
    $sFileUrl = CombinePaths($sFileUrl, $sFileName);
    if ($CKEcallback == '') {
        SendUploadResults($sErrorNumber, $sFileUrl, $sFileName);
    } else {
        //issue the CKEditor Callback
        //SendCKEditorResults($sErrorNumber, $CKEcallback, WEB_URL.'/'.$sFileUrl, $sFileName);
        SendCKEditorResults($sErrorNumber, $CKEcallback, $sFileUrl, $sFileName, $customError == "" ? "" : $customError);
    }
    exit;
}
Ejemplo n.º 9
0
function FileUpload($resourceType, $currentFolder, $sCommand)
{
    if (!isset($_FILES)) {
        global $_FILES;
    }
    $sErrorNumber = '0';
    $sFileName = '';
    if (isset($_FILES['NewFile']) && !is_null($_FILES['NewFile']['tmp_name'])) {
        global $Config;
        $oFile = $_FILES['NewFile'];
        // Map the virtual path to the local server path.
        $sServerDir = ServerMapFolder($resourceType, $currentFolder, $sCommand);
        // Get the uploaded file name.
        $sFileName = $oFile['name'];
        $sFileName = SanitizeFileName($sFileName);
        $sOriginalFileName = $sFileName;
        // Get the extension.
        $sExtension = substr($sFileName, strrpos($sFileName, '.') + 1);
        $sExtension = strtolower($sExtension);
        if (isset($Config['SecureImageUploads'])) {
            if (($isImageValid = IsImageValid($oFile['tmp_name'], $sExtension)) === false) {
                $sErrorNumber = '202';
            }
        }
        if (isset($Config['HtmlExtensions'])) {
            if (!IsHtmlExtension($sExtension, $Config['HtmlExtensions']) && ($detectHtml = DetectHtml($oFile['tmp_name'])) === true) {
                $sErrorNumber = '202';
            }
        }
        // hack for XOOPS CHINA by ezsky < *****@*****.** >
        $name_pattern = "";
        if (!empty($Config['UserFilesNamePattern'])) {
            $patterns = explode("|", $Config['UserFilesNamePattern']);
            $delimiter = "";
            foreach ($patterns as $pattern) {
                switch ($pattern) {
                    case "date":
                        $name_pattern .= $delimiter . date("YmdHis");
                        break;
                    case "time":
                        $name_pattern .= $delimiter . strval(time());
                        break;
                    case "uid":
                        $name_pattern .= $delimiter . (is_object($GLOBALS["xoopsUser"]) ? str_pad($GLOBALS["xoopsUser"]->getVar("uid"), 10, "0", STR_PAD_LEFT) : "0");
                        break;
                }
                $delimiter = "-";
            }
        }
        if (!empty($name_pattern)) {
            $sFileName = $name_pattern . "." . $sExtension;
        }
        if (!empty($Config['UserFilesPathPattern'])) {
            $sServerDir .= date($Config['UserFilesPathPattern']) . '/';
            CreateServerFolder($sServerDir);
            if (is_dir($sServerDir)) {
                $currentFolder .= date($Config['UserFilesPathPattern']) . '/';
            }
        }
        // end hack
        // Check if it is an allowed extension.
        if (!$sErrorNumber && IsAllowedExt($sExtension, $resourceType)) {
            $iCounter = 0;
            while (true) {
                $sFilePath = $sServerDir . $sFileName;
                if (is_file($sFilePath)) {
                    $iCounter++;
                    $sFileName = RemoveExtension($sOriginalFileName) . '(' . $iCounter . ').' . $sExtension;
                    $sErrorNumber = '201';
                } else {
                    move_uploaded_file($oFile['tmp_name'], $sFilePath);
                    if (is_file($sFilePath)) {
                        if (isset($Config['ChmodOnUpload']) && !$Config['ChmodOnUpload']) {
                            break;
                        }
                        $permissions = 0777;
                        if (isset($Config['ChmodOnUpload']) && $Config['ChmodOnUpload']) {
                            $permissions = $Config['ChmodOnUpload'];
                        }
                        $oldumask = umask(0);
                        chmod($sFilePath, $permissions);
                        umask($oldumask);
                    }
                    break;
                }
            }
            if (file_exists($sFilePath)) {
                //previous checks failed, try once again
                if (isset($isImageValid) && $isImageValid === -1 && IsImageValid($sFilePath, $sExtension) === false) {
                    @unlink($sFilePath);
                    $sErrorNumber = '202';
                } else {
                    if (isset($detectHtml) && $detectHtml === -1 && DetectHtml($sFilePath) === true) {
                        @unlink($sFilePath);
                        $sErrorNumber = '202';
                    }
                }
            }
        } else {
            $sErrorNumber = '202';
        }
    } else {
        $sErrorNumber = '202';
    }
    $sFileUrl = CombinePaths(GetResourceTypePath($resourceType, $sCommand), $currentFolder);
    $sFileUrl = CombinePaths($sFileUrl, $sFileName);
    SendUploadResults($sErrorNumber, $sFileUrl, $sFileName);
    exit;
}
Ejemplo n.º 10
0
function FileUpload($resourceType, $currentFolder, $sCommand)
{
    dbConn();
    $email = getEmailFCK();
    $thumb_widthpx = 160;
    if (!isset($_FILES)) {
        global $_FILES;
    }
    $sErrorNumber = '0';
    $sFileName = '';
    if (isset($_FILES['NewFile']) && !is_null($_FILES['NewFile']['tmp_name']) && $email != "") {
        global $Config;
        $oFile = $_FILES['NewFile'];
        // Map the virtual path to the local server path.
        //$sServerDir = ServerMapFolder( $resourceType, $currentFolder, $sCommand ) ;
        $s = GetRootPath() . $Config['UserTempPath'] . $currentFolder . "/";
        $s = str_replace("\\", "/", $s);
        $sServerDir = $s;
        $f = fopen("log2.txt", "a");
        fwrite($f, "\r\n  s = {$s} \r\n");
        // Get the uploaded file name.
        $sFileName = $oFile['name'];
        $sFileName = SanitizeFileName($sFileName);
        $sOriginalFileName = $sFileName;
        // Get the extension.
        $sExtension = substr($sFileName, strrpos($sFileName, '.') + 1);
        $sExtension = strtolower($sExtension);
        if (isset($Config['SecureImageUploads'])) {
            if (($isImageValid = IsImageValid($oFile['tmp_name'], $sExtension)) === false) {
                $sErrorNumber = '202';
            }
        }
        if (isset($Config['HtmlExtensions'])) {
            if (!IsHtmlExtension($sExtension, $Config['HtmlExtensions']) && ($detectHtml = DetectHtml($oFile['tmp_name'])) === true) {
                $sErrorNumber = '202';
            }
        }
        // Check if it is an allowed extension.
        if (!$sErrorNumber && IsAllowedExt($sExtension, $resourceType)) {
            $iCounter = 0;
            while (true) {
                $sFilePath = $sServerDir . "/" . $sFileName;
                //fwrite($f, "\r\n sFilePath = $sFilePath \r\n");
                //fwrite($f, "\nsServerDir = $sServerDir\n");
                if (is_file($sFilePath)) {
                    $iCounter++;
                    $sFileName = RemoveExtension($sOriginalFileName) . '(' . $iCounter . ').' . $sExtension;
                    $sErrorNumber = '201';
                } else {
                    move_uploaded_file($oFile['tmp_name'], $sFilePath);
                    if (is_file($sFilePath)) {
                        $ftype = $_FILES['NewFile']['type'];
                        $file_size = $_FILES['NewFile']['size'];
                        $originalpic = file_get_contents($sFilePath);
                        list($width, $height) = getimagesize($sFilePath);
                        if ($width > $thumb_widthpx) {
                            $count = 1;
                            $p = str_replace($sFileName, "", $sFilePath, $count);
                            //fwrite($f, "\r\nfpath: $sFilePath\r\n");
                            $thumbpic = getThumbImage($p, $thumb_widthpx, $sFileName);
                        } else {
                            $thumbpic = $originalpic;
                            unlink($sFilePath);
                        }
                        $album_id = getAlbumId($email);
                        $table = 'user_imgs';
                        $fields = array('id', 'user_email', 'large_image', 'thumb_image', 'file_type', 'stat', 'file_name', 'file_size', 'album_id', 'admin_perm', 'view_count', 'rating');
                        $values = array(null, $email, $originalpic, $thumbpic, $ftype, 1, $sFileName, $file_size, $album_id, 1, 0, 0);
                        $rs = insertData($table, $fields, $values);
                        if (is_string($rs) || $rs == false) {
                            //$sErrorNumber = '202' ;
                            //file_put_contents("$sFileName", $thumbpic);
                        } else {
                            //fwrite($f, "is inserted = true");
                        }
                        if (isset($Config['ChmodOnUpload']) && !$Config['ChmodOnUpload']) {
                            break;
                        }
                        $permissions = 0777;
                        if (isset($Config['ChmodOnUpload']) && $Config['ChmodOnUpload']) {
                            $permissions = $Config['ChmodOnUpload'];
                        }
                        $oldumask = umask(0);
                        chmod($sFilePath, $permissions);
                        umask($oldumask);
                    }
                    break;
                }
            }
            if (file_exists($sFilePath)) {
                //previous checks failed, try once again
                if (isset($isImageValid) && $isImageValid === -1 && IsImageValid($sFilePath, $sExtension) === false) {
                    @unlink($sFilePath);
                    $sErrorNumber = '202';
                } else {
                    if (isset($detectHtml) && $detectHtml === -1 && DetectHtml($sFilePath) === true) {
                        @unlink($sFilePath);
                        $sErrorNumber = '202';
                    }
                }
            }
        } else {
            $sErrorNumber = '202';
        }
    } else {
        $sErrorNumber = '202';
    }
    $sFileUrl = CombinePaths(GetResourceTypePath($resourceType, $sCommand), $currentFolder);
    $sFileUrl = CombinePaths($sFileUrl, $sFileName);
    SendUploadResults($sErrorNumber, $sFileUrl, $sFileName);
    exit;
}
Ejemplo n.º 11
0
}
echo "<tr><td  align='right'>" . $locale['LKROAX105'] . "</td>\n<td><select name='access' class='textbox'>\n<option selected value='" . $check . "'>{$group}\n{$visibility_opts}</select></td>";
echo '<tr><td colspan="2" align="center">
<input type="hidden" name="action" value="loaditems">
<input class="button" type="submit" value="' . $locale['LKROAX106'] . '">
</td></tr></table></form>';
if (isset($action) == 'loaditems') {
    if ($_POST['loadcat'] || $_POST['loadcat'] != '') {
        $embed = "";
        $uploader = $userdata['user_name'];
        $lastplayed = "0";
        $downloads = "0";
        $hits = "0";
        $catid = $_POST['loadcat'];
        $upload_folder = "" . $settings['siteurl'] . "infusions/the_kroax/uploads/movies/";
        $photo_dest = "" . $settings['siteurl'] . "infusions/the_kroax/uploads/thumbs/";
        $getname = dbarray(dbquery("select * from " . $db_prefix . "kroax_kategori WHERE cid='" . $catid . "'"));
        $movie = $_POST['movie'];
        if ($movie) {
            foreach ($movie as $t) {
                $itemname = RemoveExtension($t);
                $thumbfile = RemoveExtension($t) . '.gif';
                $moviefile = $t;
                $result = dbquery("INSERT INTO " . $db_prefix . "kroax VALUES('', '{$itemname}', '{$catid}', '" . $_POST['access'] . "', '0', '" . time() . "', '{$embed}', '{$uploader}', '{$lastplayed}','', '" . $upload_folder . "" . $moviefile . "', '{$downloads}', '{$hits}', '" . $_POST['description'] . "', '" . $photo_dest . "" . $thumbfile . "', '')");
                echo "<center>File: <font color = 'red'><b> " . $itemname . " </b></font>" . $locale['LKROAX102'] . " <font color = 'red'><b>" . $getname['title'] . "</b></font> " . $locale['LKROAX103'] . "<br></center>";
            }
        }
    } else {
        echo "<font color = 'red'><b>" . $locale['LKROAX104'] . " </b></font>";
    }
}
Ejemplo n.º 12
0
    //grab the data
    $result = mysql_query($SQL);
    $num_rows = mysql_num_rows($result);
    //check if appropriate mp4 files exists for each recording
    while ($db_field = mysql_fetch_assoc($result)) {
        if (!file_exists($mythtvdata_ . RemoveExtension($db_field['basename']) . ".mp4")) {
            $num_rows = $num_rows - 1;
        }
    }
    //print the xml header
    print "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> \n\t<feed>\n\t<!-- resultLength indicates the total number of results for this feed -->\n\t<resultLength>" . $num_rows . "</resultLength>\n\t<!-- endIndix  indicates the number of results for this *paged* section of the feed -->\n\t<endIndex>" . $num_rows . "</endIndex>";
    //reset pointer
    mysql_data_seek($result, 0);
    while ($db_field = mysql_fetch_assoc($result)) {
        //only show mp4 recordings
        if (file_exists($mythtvdata_ . RemoveExtension($db_field['basename']) . ".mp4")) {
            //compute the length of the show
            $ShowLength = convert_datetime($db_field['endtime']) - convert_datetime($db_field['starttime']);
            //print out all the records in xml format for roku to read
            print "\t\n\t\t<item sdImg=\"" . $WebServer . "/tv/get_pixmap/" . $db_field['hostname'] . "/" . $db_field['chanid'] . "/" . convert_datetime($db_field['starttime']) . "/100/75/-1/" . $db_field['basename'] . ".100x75x-1.png\" hdImg=\"" . $WebServer . "/tv/get_pixmap/" . $db_field['hostname'] . "/" . $db_field['chanid'] . "/" . convert_datetime($db_field['starttime']) . "/100/75/-1/" . $db_field['basename'] . ".100x75x-1.png\">\n\t\t\t<title>" . htmlspecialchars(preg_replace('/[^(\\x20-\\x7F)]*/', '', $db_field['title'])) . "</title>\n\t\t\t<contentId>" . $counter++ . "</contentId>\n\t\t\t<contentType>TV</contentType>\n\t\t\t<contentQuality>" . $RokuDisplayType . "</contentQuality>\n\t\t\t<media>\n\t\t\t\t<streamFormat>mp4</streamFormat>\n\t\t\t\t<streamQuality>" . $RokuDisplayType . "</streamQuality>\n\t\t\t\t<streamBitrate>" . $BitRate . "</streamBitrate>\n\t\t\t\t<streamUrl>" . $WebServer . "/pl/stream/" . $db_field['chanid'] . "/" . convert_datetime($db_field['starttime']) . ".mp4</streamUrl>\n\t\t\t</media>\n\t\t\t<synopsis>" . htmlspecialchars(preg_replace('/[^(\\x20-\\x7F)]*/', '', $db_field['description'])) . "</synopsis>\n\t\t \t<genres>" . htmlspecialchars(preg_replace('/[^(\\x20-\\x7F)]*/', '', $db_field['category'])) . "</genres>\n\t\t\t<subtitle>" . htmlspecialchars(preg_replace('/[^(\\x20-\\x7F)]*/', '', $db_field['subtitle'])) . "</subtitle>\n\t\t\t<runtime>" . $ShowLength . "</runtime>\n\t\t\t<date>" . date("F j, Y, g:i a", convert_datetime($db_field['starttime'])) . "</date>\n\t\t\t<tvormov>tv</tvormov>\n\t\t\t<delcommand>" . $WebServer . "/mythroku/mythtv_tv_del.php?basename=" . $db_field['basename'] . "</delcommand>\n\t\t</item>";
        }
    }
    print "</feed>";
} else {
    print "Database NOT Found ";
}
//close mysql pointer
mysql_close($db_handle);
//function to convert mysql timestamp to unix time
function convert_datetime($str)
{
Ejemplo n.º 13
0
                                $nrrds++;
                                break;
                            }
                        }
                    }
                    pclose($handle);
                }
            }
        }
        //      echo "<br>$i files older than ". date("Y-m-d H:i:s",$start)."<br>" ;
        $db = new ossim_db();
        $conn = $db->connect();
        echo "<center><table border=\"0\" width=\"600\">";
        for ($i = 0; $i < $nrrds; $i++) {
            echo "<tr><td style=\"padding-bottom:10px;\">";
            $ip = RemoveExtension($rrds[$i], ".rrd");
            $what = "compromise";
            ?>
        <center>
         <!--<hr width="80%">-->
         <h4><i><?php 
            echo Host::ip2hostname($conn, $ip);
            ?>
</i></h4>
         <?php 
            if ($event_perms) {
                ?>
            <a target="main" href="<?php 
                echo Util::get_acid_events_link($start_acid, $end_acid, "time_d", $ip, "ip_both");
                ?>
">
Ejemplo n.º 14
0
 function DownloadFragments($cc, $manifest, $opt = array())
 {
     $start = 0;
     extract($opt, EXTR_IF_EXISTS);
     $this->ParseManifest($cc, $manifest);
     $segNum = $this->segStart;
     $fragNum = $this->fragStart;
     if ($start) {
         if ($segNum > 1) {
             if ($start % $this->fragsPerSeg) {
                 $segNum = (int) ($start / $this->fragsPerSeg + 1);
             } else {
                 $segNum = (int) ($start / $this->fragsPerSeg);
             }
         }
         $fragNum = $start - 1;
         $this->segStart = $segNum;
         $this->fragStart = $fragNum;
     }
     $this->lastFrag = $fragNum;
     $opt['cc'] = $cc;
     $opt['duration'] = 0;
     // Extract baseFilename
     $this->baseFilename = $this->media['url'];
     if (substr($this->baseFilename, -1) == '/') {
         $this->baseFilename = substr($this->baseFilename, 0, -1);
     }
     $this->baseFilename = RemoveExtension($this->baseFilename);
     if (strrpos($this->baseFilename, '/')) {
         $this->baseFilename = substr($this->baseFilename, strrpos($this->baseFilename, '/') + 1);
     }
     if (strpos($manifest, "?")) {
         $this->baseFilename = md5(substr($manifest, 0, strpos($manifest, "?"))) . "_" . $this->baseFilename;
     } else {
         $this->baseFilename = md5($manifest) . "_" . $this->baseFilename;
     }
     $this->baseFilename .= "Seg" . $segNum . "-Frag";
     if ($fragNum >= $this->fragCount) {
         LogError("No fragment available for downloading");
     }
     if (isHttpUrl($this->media['url'])) {
         $this->fragUrl = $this->media['url'];
     } else {
         $this->fragUrl = $this->baseUrl . "/" . $this->media['url'];
     }
     $this->fragUrl = NormalizePath($this->fragUrl);
     LogDebug("Base Fragment Url:\n" . $this->fragUrl . "\n");
     LogDebug("Downloading Fragments:\n");
     while ($fragNum < $this->fragCount or $cc->active) {
         while (count($cc->ch) < $this->parallel and $fragNum < $this->fragCount) {
             $frag = array();
             $fragNum = $fragNum + 1;
             $frag['id'] = $fragNum;
             LogInfo("Downloading {$fragNum}/{$this->fragCount} fragments", true);
             if (in_array_field($fragNum, "firstFragment", $this->fragTable, true)) {
                 $this->discontinuity = value_in_array_field($fragNum, "firstFragment", "discontinuityIndicator", $this->fragTable, true);
             } else {
                 $closest = 1;
                 foreach ($this->fragTable as $item) {
                     if ($item['firstFragment'] < $fragNum) {
                         $closest = $item['firstFragment'];
                     } else {
                         break;
                     }
                 }
                 $this->discontinuity = value_in_array_field($closest, "firstFragment", "discontinuityIndicator", $this->fragTable, true);
             }
             if ($this->discontinuity == 1 or $this->discontinuity == 3) {
                 LogDebug("Skipping fragment {$fragNum} due to discontinuity");
                 $frag['response'] = false;
                 $this->rename = true;
             } else {
                 if (file_exists($this->baseFilename . $fragNum)) {
                     LogDebug("Fragment {$fragNum} is already downloaded");
                     $frag['response'] = file_get_contents($this->baseFilename . $fragNum);
                 }
             }
             if (isset($frag['response'])) {
                 if ($this->WriteFragment($frag, $opt) === 2) {
                     break 2;
                 } else {
                     continue;
                 }
             }
             /* Increase or decrease segment number if current fragment is not available */
             /* in selected segment range                                                */
             if (count($this->segTable) > 1) {
                 if ($fragNum > $segNum * $this->fragsPerSeg) {
                     $segNum++;
                 } else {
                     if ($fragNum <= ($segNum - 1) * $this->fragsPerSeg) {
                         $segNum--;
                     }
                 }
             }
             LogDebug("Adding fragment {$fragNum} to download queue");
             $cc->addDownload($this->fragUrl . "Seg" . $segNum . "-Frag" . $fragNum . $this->auth, $fragNum);
         }
         $downloads = $cc->checkDownloads();
         if ($downloads !== false) {
             for ($i = 0; $i < count($downloads); $i++) {
                 $frag = array();
                 $download = $downloads[$i];
                 $frag['id'] = $download['id'];
                 if ($download['status'] == 200) {
                     if ($this->VerifyFragment($download['response'])) {
                         LogDebug("Fragment " . $this->baseFilename . $download['id'] . " successfully downloaded");
                         if (!($this->live or $this->play)) {
                             file_put_contents($this->baseFilename . $download['id'], $download['response']);
                         }
                         $frag['response'] = $download['response'];
                     } else {
                         LogDebug("Fragment " . $download['id'] . " failed to verify");
                         LogDebug("Adding fragment " . $download['id'] . " to download queue");
                         $cc->addDownload($download['url'], $download['id']);
                     }
                 } else {
                     if ($download['status'] === false) {
                         LogDebug("Fragment " . $download['id'] . " failed to download");
                         LogDebug("Adding fragment " . $download['id'] . " to download queue");
                         $cc->addDownload($download['url'], $download['id']);
                     } else {
                         if ($download['status'] == 403) {
                             LogError("Access Denied! Unable to download fragments.");
                         } else {
                             LogDebug("Fragment " . $download['id'] . " doesn't exist, Status: " . $download['status']);
                             $frag['response'] = false;
                             $this->rename = true;
                             /* Resync with latest available fragment when we are left behind due to */
                             /* slow connection and short live window on streaming server. make sure */
                             /* to reset the last written fragment.                                  */
                             if ($this->live and $i + 1 == count($downloads) and !$cc->active) {
                                 LogDebug("Trying to resync with latest available fragment");
                                 if ($this->WriteFragment($frag, $opt) === 2) {
                                     break 2;
                                 }
                                 unset($frag['response']);
                                 $this->UpdateBootstrapInfo($cc, $this->bootstrapUrl);
                                 $fragNum = $this->fragCount - 1;
                                 $this->lastFrag = $fragNum;
                             }
                         }
                     }
                 }
                 if (isset($frag['response'])) {
                     if ($this->WriteFragment($frag, $opt) === 2) {
                         break 2;
                     }
                 }
             }
             unset($downloads, $download);
         }
         if ($this->live and $fragNum >= $this->fragCount and !$cc->active) {
             $this->UpdateBootstrapInfo($cc, $this->bootstrapUrl);
         }
     }
     LogInfo("");
     LogDebug("\nAll fragments downloaded successfully\n");
     $cc->stopDownloads();
     $this->processed = true;
 }
Ejemplo n.º 15
0
function FileUpload($resourceType, $currentFolder, $sCommand)
{
    if (!isset($_FILES)) {
        global $_FILES;
    }
    $sErrorNumber = '0';
    $sFileName = '';
    if (isset($_FILES['NewFile']) && !is_null($_FILES['NewFile']['tmp_name'])) {
        global $Config;
        $oFile = $_FILES['NewFile'];
        // Map the virtual path to the local server path.
        $sServerDir = ServerMapFolder($resourceType, $currentFolder, $sCommand);
        // Get the uploaded file name.
        $sFileName = $oFile['name'];
        $sFileName = SanitizeFileName($sFileName, $oFile['type']);
        $sOriginalFileName = $sFileName;
        // Get the extension.
        $sExtension = substr($sFileName, strrpos($sFileName, '.') + 1);
        $sExtension = strtolower($sExtension);
        if (isset($Config['SecureImageUploads'])) {
            if (($isImageValid = IsImageValid($oFile['tmp_name'], $sExtension)) === false) {
                $sErrorNumber = '202';
            }
        }
        if (isset($Config['HtmlExtensions'])) {
            if (!IsHtmlExtension($sExtension, $Config['HtmlExtensions']) && ($detectHtml = DetectHtml($oFile['tmp_name'])) === true) {
                $sErrorNumber = '202';
            }
        }
        // Check if it is an allowed extension.
        if (!$sErrorNumber && IsAllowedExt($sExtension, $resourceType)) {
            $iCounter = 0;
            while (true) {
                $sFilePath = $sServerDir . $sFileName;
                if (is_file($sFilePath)) {
                    $iCounter++;
                    $sFileName = RemoveExtension($sOriginalFileName) . '(' . $iCounter . ').' . $sExtension;
                    $sErrorNumber = '0';
                    // Change $sErrorNumber '201' to '0' to allow create record files renamed
                } else {
                    move_uploaded_file($oFile['tmp_name'], $sFilePath);
                    if (is_file($sFilePath)) {
                        if (isset($Config['ChmodOnUpload']) && !$Config['ChmodOnUpload']) {
                            break;
                        }
                        $permissions = 0777;
                        if (isset($Config['ChmodOnUpload']) && $Config['ChmodOnUpload']) {
                            $permissions = $Config['ChmodOnUpload'];
                        }
                        //$oldumask = umask(0) ;
                        chmod($sFilePath, $permissions);
                        //umask( $oldumask ) ;
                    }
                    break;
                }
            }
            if (file_exists($sFilePath)) {
                //previous checks failed, try once again
                if (isset($isImageValid) && $isImageValid === -1 && IsImageValid($sFilePath, $sExtension) === false) {
                    @unlink($sFilePath);
                    $sErrorNumber = '202';
                } else {
                    if (isset($detectHtml) && $detectHtml === -1 && DetectHtml($sFilePath) === true) {
                        @unlink($sFilePath);
                        $sErrorNumber = '202';
                    }
                }
            }
        } else {
            $sErrorNumber = '202';
        }
    } else {
        $sErrorNumber = '202';
    }
    if ($sErrorNumber == '0') {
        // While we are in a course: Registering the newly uploaded file in the course's database.
        if (api_is_in_course()) {
            global $_course, $_user;
            $repository_path = api_get_path(REL_COURSE_PATH) . api_get_course_path() . '/document/';
            $to_group_id = 0;
            if (api_is_in_group()) {
                global $group_properties;
                $to_group_id = $group_properties['id'];
            }
            if (file_exists($sFilePath)) {
                $file_path = substr($sFilePath, strpos($sFilePath, $repository_path) + strlen($repository_path) - 1);
                $path = explode('/', $file_path);
                $file_name = $path[count($path) - 1];
                $path[count($path) - 1] = '';
                $folder_path = '/' + implode('/', $path);
                $file_size = @filesize($sFilePath);
                $doc_id = add_document($_course, $file_path, 'file', $file_size, $file_name);
                api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'], $to_group_id);
                item_property_update_on_folder($_course, $folder_path, $_user['user_id']);
            }
        }
    }
    $sFileUrl = CombinePaths(GetResourceTypePath($resourceType, $sCommand), $currentFolder);
    $sFileUrl = CombinePaths($sFileUrl, $sFileName);
    SendUploadResults($sErrorNumber, $sFileUrl, $sFileName);
    exit;
}
Ejemplo n.º 16
0
function FileUpload($resourceType, $currentFolder, $sCommand)
{
    global $dwfck_conf;
    if (!isset($_FILES)) {
        global $_FILES;
    }
    $sErrorNumber = '0';
    $sFileName = '';
    $sess_id = session_id();
    if (!isset($sess_id) || $sess_id != $_COOKIE['FCK_NmSp_acl']) {
        session_id($_COOKIE['FCK_NmSp_acl']);
        session_start();
    }
    global $Dwfck_conf_values;
    $dwfck_conf = $_SESSION['dwfck_conf'];
    if (empty($dwfck_conf)) {
        $dwfck_conf['deaccent'] = isset($Dwfck_conf_values['deaccent']) ? $Dwfck_conf_values['deaccent'] : 1;
        $dwfck_conf['useslash'] = isset($Dwfck_conf_values['useslash']) ? $Dwfck_conf_values['useslash'] : 0;
        $dwfck_conf['sepchar'] = isset($Dwfck_conf_values['sepchar']) ? $Dwfck_conf_values['sepchar'] : '_';
    }
    $auth = 0;
    if (isset($_REQUEST['TopLevel'])) {
        list($top_level, $auth) = explode(';;', $_REQUEST['TopLevel']);
    }
    $safe = false;
    global $Dwfck_conf_values;
    if ($Dwfck_conf_values['fnencode'] == 'safe') {
        if (preg_match('/%[a-z]+[0-9]/', $currentFolder) || preg_match('/%[0-9][a-z]/', $currentFolder)) {
            $safe = true;
        }
    }
    $ns_tmp = dwiki_decodeFN(trim($currentFolder, '/'));
    $ns_tmp = str_replace('/', ':', $ns_tmp);
    $test = $ns_tmp . ':*';
    if (!$safe) {
        $test = urldecode($test);
        while (preg_match('/%25/', $test)) {
            $test = urldecode($test);
        }
        $test = urldecode($test);
    }
    $isadmin = isset($_SESSION['dwfck_conf']['isadmin']) ? $_SESSION['dwfck_conf']['isadmin'] : false;
    if (!$isadmin) {
        $AUTH = auth_aclcheck($test, $_SESSION['dwfck_client'], $_SESSION['dwfck_grps'], 1);
        if ($AUTH < 8) {
            $msg = "";
            $sFileUrl = CombinePaths(GetResourceTypePath($resourceType, $sCommand), $currentFolder);
            $sFileUrl = CombinePaths($sFileUrl, $_FILES['NewFile']['name']);
            SendUploadResults('203', $sFileUrl, htmlentities($_FILES['NewFile']['name']), $msg);
            return;
        }
    }
    if (!$safe) {
        $currentFolder = encode_dir($currentFolder);
    }
    if (isset($_FILES['NewFile']) && !is_null($_FILES['NewFile']['tmp_name'])) {
        global $Config;
        $upload_err = $_FILES['NewFile']['error'];
        if ($upload_err) {
            send_ckg_UploadError($upload_err, $sFileUrl, htmlentities($_FILES['NewFile']['name']));
            exit;
        }
        $oFile = $_FILES['NewFile'];
        // Map the virtual path to the local server path.
        $sServerDir = ServerMapFolder($resourceType, $currentFolder, $sCommand);
        // Get the uploaded file name.
        $sFileName = dwiki_encodeFN($oFile['name']);
        $sOriginalFileName = dwiki_encodeFN($sFileName);
        // Get the extension.
        $sExtension = substr($sFileName, strrpos($sFileName, '.') + 1);
        $sExtension = strtolower($sExtension);
        $image_file = false;
        if (in_array($sExtension, $Config['AllowedExtensions']['Image'])) {
            $image_file = true;
        }
        if (isset($Config['SecureImageUploads'])) {
            if (($isImageValid = IsImageValid($oFile['tmp_name'], $sExtension)) === false) {
                $sErrorNumber = '202';
            }
        }
        if (isset($Config['HtmlExtensions'])) {
            if (!IsHtmlExtension($sExtension, $Config['HtmlExtensions']) && ($detectHtml = DetectHtml($oFile['tmp_name'])) === true) {
                $sErrorNumber = '202';
            }
        }
        $sFileName = Dwfck_sanitize($sFileName, $image_file);
        // Check if it is an allowed extension.
        if (!$sErrorNumber && IsAllowedExt($sExtension, $resourceType)) {
            $iCounter = 0;
            while (true) {
                //$sFileName = strtolower($sFileName);
                if (!is_dir($sServerDir)) {
                    if (isset($Config['ChmodOnFolderCreate']) && !$Config['ChmodOnFolderCreate']) {
                        mkdir_rek($sServerDir, $permissions);
                    } else {
                        $permissions = 0777;
                        if (isset($Config['ChmodOnFolderCreate'])) {
                            $permissions = $Config['ChmodOnFolderCreate'];
                        }
                        // To create the folder with 0777 permissions, we need to set umask to zero.
                        $oldumask = umask(0);
                        mkdir_rek($sServerDir, $permissions);
                        umask($oldumask);
                    }
                }
                $sFilePath = $sServerDir . $sFileName;
                if (is_file($sFilePath)) {
                    $iCounter++;
                    if ($Dwfck_conf_values['fnencode'] == 'safe') {
                        $sFileName = RemoveExtension(dwiki_decodeFN($sOriginalFileName)) . '_' . $iCounter . ".{$sExtension}";
                    } else {
                        $sFileName = RemoveExtension($sOriginalFileName) . '_' . $iCounter . ".{$sExtension}";
                    }
                    $sFileName = Dwfck_sanitize($sFileName, $image_file);
                    $sErrorNumber = '201';
                } else {
                    move_uploaded_file($oFile['tmp_name'], $sFilePath);
                    if (is_file($sFilePath)) {
                        if (isset($Config['ChmodOnUpload']) && !$Config['ChmodOnUpload']) {
                            break;
                        }
                        $permissions = 0777;
                        if (isset($Config['ChmodOnUpload']) && $Config['ChmodOnUpload']) {
                            $permissions = $Config['ChmodOnUpload'];
                        }
                        $oldumask = umask(0);
                        chmod($sFilePath, $permissions);
                        umask($oldumask);
                    }
                    break;
                }
            }
            if (file_exists($sFilePath)) {
                //previous checks failed, try once again
                if (isset($isImageValid) && $isImageValid === -1 && IsImageValid($sFilePath, $sExtension) === false) {
                    @unlink($sFilePath);
                    $sErrorNumber = '202';
                } else {
                    if (isset($detectHtml) && $detectHtml === -1 && DetectHtml($sFilePath) === true) {
                        @unlink($sFilePath);
                        $sErrorNumber = '202';
                    }
                }
            }
        } else {
            $sErrorNumber = '202';
        }
    } else {
        $sErrorNumber = '202';
    }
    $sFileUrl = CombinePaths(GetResourceTypePath($resourceType, $sCommand), $currentFolder);
    $sFileUrl = CombinePaths($sFileUrl, $sFileName);
    SendUploadResults($sErrorNumber, $sFileUrl, htmlentities($sFileName));
    exit;
}
Ejemplo n.º 17
0
function MoreFileUpload($resourceType, $currentFolder, $sCommand)
{
    if (!isset($_FILES)) {
        global $_FILES;
    }
    global $Config;
    $sErrorNumber = '0';
    $sFileName = '';
    if (is_array($_FILES['NewFile']['name'])) {
        foreach ($_FILES['NewFile']['name'] as $key => $value) {
            if (!empty($_FILES['NewFile']['tmp_name'][$key])) {
                // Map the virtual path to the local server path.
                $sServerDir = ServerMapFolder($resourceType, $currentFolder, $sCommand);
                // Get the uploaded file name.
                $sFileName = $_FILES['NewFile']['name'][$key];
                $sFileName = SanitizeFileName($sFileName);
                $sOriginalFileName = $sFileName;
                // Get the extension.
                $sExtension = substr($sFileName, strrpos($sFileName, '.') + 1);
                $sExtension = strtolower($sExtension);
                if (isset($Config['SecureImageUploads'])) {
                    if (($isImageValid = IsImageValid($_FILES['NewFile']['tmp_name'][$key], $sExtension)) === false) {
                        $sErrorNumber = '202';
                    }
                }
                if (isset($Config['HtmlExtensions'])) {
                    if (!IsHtmlExtension($sExtension, $Config['HtmlExtensions']) && ($detectHtml = DetectHtml($_FILES['NewFile']['tmp_name'][$key])) === true) {
                        $sErrorNumber = '202';
                    }
                }
                // Check if it is an allowed extension.
                if (!$sErrorNumber && IsAllowedExt($sExtension, $resourceType)) {
                    $iCounter = 0;
                    while (true) {
                        $sFilePath = $sServerDir . $sFileName;
                        if (is_file($sFilePath)) {
                            $iCounter++;
                            $sFileName = RemoveExtension($sOriginalFileName) . '(' . $iCounter . ').' . $sExtension;
                            $sErrorNumber = '201';
                        } else {
                            move_uploaded_file($_FILES['NewFile']['tmp_name'][$key], $sFilePath);
                            //判断并给符合条件图片加上水印
                            if ($sExtension == 'jpg' || $sExtension == 'jpeg' || $sExtension == 'png' || $sExtension == 'gif' || $sExtension == 'bmp') {
                                require_once ROOT_PATH . '/includes/cls_image.php';
                                $image = new cls_image($GLOBALS['_CFG']['bgcolor']);
                                if (intval($GLOBALS['_CFG']['watermark_place']) > 0 && !empty($GLOBALS['_CFG']['watermark'])) {
                                    $image->add_watermark($sFilePath, '', '../../../../../' . $GLOBALS['_CFG']['watermark'], $GLOBALS['_CFG']['watermark_place'], $GLOBALS['_CFG']['watermark_alpha']);
                                }
                            }
                            if (is_file($sFilePath)) {
                                if (isset($Config['ChmodOnUpload']) && !$Config['ChmodOnUpload']) {
                                    break;
                                }
                                $permissions = 0777;
                                if (isset($Config['ChmodOnUpload']) && $Config['ChmodOnUpload']) {
                                    $permissions = $Config['ChmodOnUpload'];
                                }
                                $oldumask = umask(0);
                                chmod($sFilePath, $permissions);
                                umask($oldumask);
                            }
                            break;
                        }
                    }
                    if (file_exists($sFilePath)) {
                        //previous checks failed, try once again
                        if (isset($isImageValid) && $isImageValid === -1 && IsImageValid($sFilePath, $sExtension) === false) {
                            @unlink($sFilePath);
                            $sErrorNumber = '202';
                        } else {
                            if (isset($detectHtml) && $detectHtml === -1 && DetectHtml($sFilePath) === true) {
                                @unlink($sFilePath);
                                $sErrorNumber = '202';
                            }
                        }
                    }
                } else {
                    $sErrorNumber = '202';
                }
                if ($sErrorNumber == '202') {
                    $sFileUrl = CombinePaths(GetResourceTypePath($resourceType, $sCommand), $currentFolder);
                    $sFileUrl = CombinePaths($sFileUrl, $sFileName);
                    SendUploadResults($sErrorNumber, $sFileUrl, $sFileName);
                }
            } else {
                continue;
            }
        }
        $sFileUrl = CombinePaths(GetResourceTypePath($resourceType, $sCommand), $currentFolder);
        $sFileUrl = CombinePaths($sFileUrl, $sFileName);
        SendUploadResults($sErrorNumber, $sFileUrl, $sFileName, $key);
    } else {
        $sErrorNumber = '202';
        $sFileUrl = CombinePaths(GetResourceTypePath($resourceType, $sCommand), $currentFolder);
        $sFileUrl = CombinePaths($sFileUrl, $sFileName);
        SendUploadResults($sErrorNumber, $sFileUrl, $sFileName);
    }
    exit;
}
Ejemplo n.º 18
0
function FileUpload($resourceType, $currentFolder, $sCommand)
{
    if (!isset($_FILES)) {
        global $_FILES;
    }
    $sErrorNumber = '0';
    $sFileName = '';
    if (isset($_FILES['NewFile']) && !is_null($_FILES['NewFile']['tmp_name'])) {
        global $Config;
        $oFile = $_FILES['NewFile'];
        // Map the virtual path to the local server path.
        $sServerDir = ServerMapFolder($resourceType, $currentFolder, $sCommand);
        // Get the uploaded file name.
        $sFileName = $oFile['name'];
        $sFileName = SanitizeFileName($sFileName);
        $sOriginalFileName = $sFileName;
        // Get the extension.
        $sExtension = substr($sFileName, strrpos($sFileName, '.') + 1);
        $sExtension = strtolower($sExtension);
        if (isset($Config['SecureImageUploads'])) {
            if (($isImageValid = IsImageValid($oFile['tmp_name'], $sExtension)) === false) {
                $sErrorNumber = '202';
            }
        }
        if (isset($Config['HtmlExtensions'])) {
            if (!IsHtmlExtension($sExtension, $Config['HtmlExtensions']) && ($detectHtml = DetectHtml($oFile['tmp_name'])) === true) {
                $sErrorNumber = '202';
            }
        }
        // Check if it is an allowed extension.
        if (!$sErrorNumber && IsAllowedExt($sExtension, $resourceType)) {
            $iCounter = 0;
            while (true) {
                $sFilePath = $sServerDir . $sFileName;
                if (is_file($sFilePath)) {
                    $iCounter++;
                    $sFileName = RemoveExtension($sOriginalFileName) . '(' . $iCounter . ').' . $sExtension;
                    $sErrorNumber = '201';
                } else {
                    move_uploaded_file($oFile['tmp_name'], $sFilePath);
                    if (is_file($sFilePath)) {
                        if (isset($Config['ChmodOnUpload']) && !$Config['ChmodOnUpload']) {
                            break;
                        }
                        $permissions = 0777;
                        if (isset($Config['ChmodOnUpload']) && $Config['ChmodOnUpload']) {
                            $permissions = $Config['ChmodOnUpload'];
                        }
                        $oldumask = umask(0);
                        chmod($sFilePath, $permissions);
                        umask($oldumask);
                    }
                    break;
                }
            }
            if (file_exists($sFilePath)) {
                //previous checks failed, try once again
                if (isset($isImageValid) && $isImageValid === -1 && IsImageValid($sFilePath, $sExtension) === false) {
                    @unlink($sFilePath);
                    $sErrorNumber = '202';
                } else {
                    if (isset($detectHtml) && $detectHtml === -1 && DetectHtml($sFilePath) === true) {
                        @unlink($sFilePath);
                        $sErrorNumber = '202';
                    }
                }
            }
        } else {
            $sErrorNumber = '202';
        }
    } else {
        $sErrorNumber = '202';
    }
    $sFileUrl = CombinePaths(GetResourceTypePath($resourceType, $sCommand), $currentFolder);
    $sFileUrl = CombinePaths($sFileUrl, $sFileName);
    SendUploadResults($sErrorNumber, $sFileUrl, $sFileName);
    exit;
}
Ejemplo n.º 19
0
function FileUpload($resourceType, $currentFolder, $sCommand, $CKEcallback = '')
{
    if (!isset($_FILES)) {
        global $_FILES;
    }
    $sErrorNumber = '0';
    $sFileName = '';
    if (isset($_FILES['NewFile']) && !is_null($_FILES['NewFile']['tmp_name']) || isset($_FILES['upload']) && !is_null($_FILES['upload']['tmp_name'])) {
        global $Config;
        $oFile = isset($_FILES['NewFile']) ? $_FILES['NewFile'] : $_FILES['upload'];
        // Map the virtual path to the local server path.
        $sServerDir = ServerMapFolder($resourceType, $currentFolder, $sCommand);
        // Get the uploaded file name.
        $sFileName = filemanager_translit($oFile['name']);
        $sFileName = SanitizeFileName($sFileName);
        $sOriginalFileName = $sFileName;
        // Get the extension.
        $sExtension = substr($sFileName, strrpos($sFileName, '.') + 1);
        $sExtension = strtolower($sExtension);
        if (isset($Config['SecureImageUploads'])) {
            if (($isImageValid = IsImageValid($oFile['tmp_name'], $sExtension)) === false) {
                $sErrorNumber = '202';
            }
        }
        if (isset($Config['HtmlExtensions'])) {
            if (!IsHtmlExtension($sExtension, $Config['HtmlExtensions']) && ($detectHtml = DetectHtml($oFile['tmp_name'])) === true) {
                $sErrorNumber = '202';
            }
        }
        // Check if it is an allowed extension.
        if (!$sErrorNumber && IsAllowedExt($sExtension, $resourceType)) {
            $iCounter = 0;
            while (true) {
                $sFilePath = $sServerDir . $sFileName;
                if (is_file($sFilePath)) {
                    $iCounter++;
                    $sFileName = RemoveExtension($sOriginalFileName) . '(' . $iCounter . ').' . $sExtension;
                    $sErrorNumber = '201';
                } else {
                    move_uploaded_file($oFile['tmp_name'], $sFilePath);
                    if (is_file($sFilePath)) {
                        if (isset($Config['ChmodOnUpload']) && !$Config['ChmodOnUpload']) {
                            break;
                        }
                        $permissions = 0777;
                        if (isset($Config['ChmodOnUpload']) && $Config['ChmodOnUpload']) {
                            $permissions = $Config['ChmodOnUpload'];
                        }
                        $oldumask = umask(0);
                        chmod($sFilePath, $permissions);
                        umask($oldumask);
                        if ($Config['ThumbCreate'] && $_POST['thumb'] && in_array($sExtension, array("gif", "jpg", "jpeg", "png", "wbmp"))) {
                            filemanager_thumb($sFilePath, $_POST['thumb_x'], $_POST['thumb_y']);
                        }
                        if ($Config['ThumbList'] && $resourceType == 'Image') {
                            $sThumbPath = CombinePaths($_SERVER['DOCUMENT_ROOT'] . GetResourceTypePath('ImageThumb', 'Upload'), filemanager_getthumbname($currentFolder . $sFileName));
                            filemanager_thumb($sFilePath, $Config['ThumbListSize'], $Config['ThumbListSize'], $sThumbPath);
                        }
                    }
                    break;
                }
            }
            if (!empty($sFilePath) && file_exists($sFilePath)) {
                //previous checks failed, try once again
                if (isset($isImageValid) && $isImageValid === -1 && IsImageValid($sFilePath, $sExtension) === false) {
                    @unlink($sFilePath);
                    $sErrorNumber = '202';
                } else {
                    if (isset($detectHtml) && $detectHtml === -1 && DetectHtml($sFilePath) === true) {
                        @unlink($sFilePath);
                        $sErrorNumber = '202';
                    }
                }
            }
        } else {
            $sErrorNumber = '202';
        }
    } else {
        $sErrorNumber = '202';
    }
    $sFileUrl = CombinePaths(GetResourceTypePath($resourceType, $sCommand), $currentFolder);
    $sFileUrl = CombinePaths($sFileUrl, $sFileName);
    if ($CKEcallback == '') {
        SendUploadResults($sErrorNumber, $sFileUrl, $sFileName);
    } else {
        //issue the CKEditor Callback
        SendCKEditorResults($sErrorNumber, $CKEcallback, $sFileUrl, $sFileName);
    }
    exit;
}
Ejemplo n.º 20
0
function weird_player($file_url)
{
    global $title, $thumb, $videoimg, $file, $url, $lurl, $youtubeembedcode, $youtubedownloadcode, $locale;
    $file_url = RemoveExtension($file_url);
    $videoid = strval($file_url);
    if (preg_match('/http:\\/\\/www.youtube.com\\/watch\\?v=(.*)/', $videoid, $match)) {
        $videoid = $match[1];
    }
    $url = "http://www.youtube.com/api2_rest?method=youtube.videos.get_video_token&video_id={$videoid}";
    $t = trim(strip_tags(@file_get_contents($url)));
    $url = "http://www.youtube.com/get_video.php?video_id=" . $videoid . "&amp;t=" . $t . "&amp;fmt=18";
    $file = urlencode(trim($url, "Location: "));
    $theplayer = <<<EOD
<table border='0' cellpadding='0' align="center" style='margin: 0 auto;'>
\t<tr>
\t\t<td>
<div id="videobox3">
<a href="http://www.adobe.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">Download Flash Player</a><br>
</div>
<script type="text/javascript">
var s3 = new SWFObject("flash_flv_player/flvplayer.swf","single","420","360","7");
s3.useExpressInstall("expressinstall.swf"); 
s3.addParam("allowfullscreen","true");
s3.addVariable("autostart","false");
s3.addVariable("type","flv");
s3.addVariable("file","{$file}");
s3.addVariable("logo","{$videoimg}");
s3.addVariable("image","{$thumb}");
s3.addVariable("displayheight","340");
s3.addVariable("width","420");
s3.addVariable("height","360");
s3.write("videobox3");
</script>
<a href="download.php?url={$file}&title={$title}&youtube" target="_blank">Download</a>
{$youtubeembedcode}
\t\t</td>
\t</tr>
</table>
EOD;
    echo $theplayer;
}
Ejemplo n.º 21
0
function FileUpload($resourceType, $currentFolder)
{
    $sErrorNumber = '0';
    $sFileName = '';
    if (isset($_FILES['NewFile']) && !is_null($_FILES['NewFile']['tmp_name'])) {
        $oFile = $_FILES['NewFile'];
        // Map the virtual path to the local server path.
        $sServerDir = ServerMapFolder($resourceType, $currentFolder);
        // Get the uploaded file name.
        $sFileName = $oFile['name'];
        $sOriginalFileName = $sFileName;
        $iCounter = 0;
        while (true) {
            $sFilePath = $sServerDir . $sFileName;
            if (is_file($sFilePath)) {
                $iCounter++;
                $oPathInfo = pathinfo($sFilePath);
                $sFileName = RemoveExtension($sOriginalFileName) . '(' . $iCounter . ').' . $oPathInfo['extension'];
                $sErrorNumber = '201';
            } else {
                move_uploaded_file($oFile['tmp_name'], $sFilePath);
                break;
            }
        }
    } else {
        $sErrorNumber = '202';
    }
    echo '<script type="text/javascript">';
    echo 'window.parent.frames["frmUpload"].OnUploadCompleted(' . $sErrorNumber . ',"' . str_replace('"', '\\"', $sFileName) . '") ;';
    echo '</script>';
    exit;
}
Ejemplo n.º 22
0
 function DownloadFragments($cc, $manifest, $opt = array())
 {
     $start = 0;
     extract($opt, EXTR_IF_EXISTS);
     $this->ParseManifest($cc, $manifest);
     $segNum = $this->segStart;
     $fragNum = $this->fragStart;
     if ($start) {
         $segNum = $this->GetSegmentFromFragment($start);
         $fragNum = $start - 1;
         $this->segStart = $segNum;
         $this->fragStart = $fragNum;
     }
     $this->lastFrag = $fragNum;
     $opt['cc'] = $cc;
     $opt['duration'] = 0;
     $firstFragment = reset($this->fragTable);
     LogInfo(sprintf("Fragments Total: %s, First: %s, Start: %s, Parallel: %s", $this->fragCount, $firstFragment['firstFragment'], $fragNum + 1, $this->parallel));
     // Extract baseFilename
     $this->baseFilename = $this->media['url'];
     if (substr($this->baseFilename, -1) == '/') {
         $this->baseFilename = substr($this->baseFilename, 0, -1);
     }
     $this->baseFilename = RemoveExtension($this->baseFilename);
     $lastSlash = strrpos($this->baseFilename, '/');
     if ($lastSlash !== false) {
         $this->baseFilename = substr($this->baseFilename, $lastSlash + 1);
     }
     if (strpos($manifest, '?')) {
         $this->baseFilename = md5(substr($manifest, 0, strpos($manifest, '?'))) . '_' . $this->baseFilename;
     } else {
         $this->baseFilename = md5($manifest) . '_' . $this->baseFilename;
     }
     $this->baseFilename .= "Seg" . $segNum . "-Frag";
     if ($fragNum >= $this->fragCount) {
         LogError("No fragment available for downloading");
     }
     $this->fragUrl = AbsoluteUrl($this->baseUrl, $this->media['url']);
     LogDebug("Base Fragment Url:\n" . $this->fragUrl . "\n");
     LogDebug("Downloading Fragments:\n");
     while ($fragNum < $this->fragCount or $cc->active) {
         while (count($cc->ch) < $this->parallel and $fragNum < $this->fragCount) {
             $frag = array();
             $fragNum = $fragNum + 1;
             $frag['id'] = $fragNum;
             LogInfo("Downloading {$fragNum}/{$this->fragCount} fragments", true);
             if (in_array_field($fragNum, "firstFragment", $this->fragTable, true)) {
                 $this->discontinuity = value_in_array_field($fragNum, "firstFragment", "discontinuityIndicator", $this->fragTable, true);
             } else {
                 $closest = reset($this->fragTable);
                 $closest = $closest['firstFragment'];
                 while ($current = next($this->fragTable)) {
                     if ($current['firstFragment'] < $fragNum) {
                         $closest = $current['firstFragment'];
                     } else {
                         break;
                     }
                 }
                 $this->discontinuity = value_in_array_field($closest, "firstFragment", "discontinuityIndicator", $this->fragTable, true);
             }
             if ($this->discontinuity !== "") {
                 LogDebug("Skipping fragment {$fragNum} due to discontinuity, Type: " . $this->discontinuity);
                 $frag['response'] = false;
                 $this->rename = true;
             } else {
                 if (file_exists($this->baseFilename . $fragNum)) {
                     LogDebug("Fragment {$fragNum} is already downloaded");
                     $frag['response'] = file_get_contents($this->baseFilename . $fragNum);
                 }
             }
             if (isset($frag['response'])) {
                 if ($this->WriteFragment($frag, $opt) === STOP_PROCESSING) {
                     break 2;
                 } else {
                     continue;
                 }
             }
             LogDebug("Adding fragment {$fragNum} to download queue");
             $segNum = $this->GetSegmentFromFragment($fragNum);
             $cc->addDownload($this->fragUrl . "Seg" . $segNum . "-Frag" . $fragNum . $this->media['queryString'], $fragNum);
         }
         $downloads = $cc->checkDownloads();
         if ($downloads !== false) {
             for ($i = 0; $i < count($downloads); $i++) {
                 $frag = array();
                 $download = $downloads[$i];
                 $frag['id'] = $download['id'];
                 if ($download['status'] == 200) {
                     if ($this->VerifyFragment($download['response'])) {
                         LogDebug("Fragment " . $this->baseFilename . $download['id'] . " successfully downloaded");
                         if (!($this->live or $this->play)) {
                             file_put_contents($this->baseFilename . $download['id'], $download['response']);
                         }
                         $frag['response'] = $download['response'];
                     } else {
                         LogDebug("Fragment " . $download['id'] . " failed to verify");
                         LogDebug("Adding fragment " . $download['id'] . " to download queue");
                         $cc->addDownload($download['url'], $download['id']);
                     }
                 } else {
                     if ($download['status'] === false) {
                         LogDebug("Fragment " . $download['id'] . " failed to download");
                         LogDebug("Adding fragment " . $download['id'] . " to download queue");
                         $cc->addDownload($download['url'], $download['id']);
                     } else {
                         if ($download['status'] == 403) {
                             LogError("Access Denied! Unable to download fragments.");
                         } else {
                             if ($download['status'] == 503) {
                                 LogDebug("Fragment " . $download['id'] . " seems temporary unavailable");
                                 LogDebug("Adding fragment " . $download['id'] . " to download queue");
                                 $cc->addDownload($download['url'], $download['id']);
                             } else {
                                 LogDebug("Fragment " . $download['id'] . " doesn't exist, Status: " . $download['status']);
                                 $frag['response'] = false;
                                 $this->rename = true;
                                 /* Resync with latest available fragment when we are left behind due to slow *
                                  * connection and short live window on streaming server. make sure to reset  *
                                  * the last written fragment.                                                */
                                 if ($this->live and $fragNum >= $this->fragCount and $i + 1 == count($downloads) and !$cc->active) {
                                     LogDebug("Trying to resync with latest available fragment");
                                     if ($this->WriteFragment($frag, $opt) === STOP_PROCESSING) {
                                         break 2;
                                     }
                                     unset($frag['response']);
                                     $this->UpdateBootstrapInfo($cc, $this->bootstrapUrl);
                                     $fragNum = $this->fragCount - 1;
                                     $this->lastFrag = $fragNum;
                                 }
                             }
                         }
                     }
                 }
                 if (isset($frag['response'])) {
                     if ($this->WriteFragment($frag, $opt) === STOP_PROCESSING) {
                         break 2;
                     }
                 }
             }
             unset($downloads, $download);
         }
         if ($this->live and $fragNum >= $this->fragCount and !$cc->active) {
             $this->UpdateBootstrapInfo($cc, $this->bootstrapUrl);
         }
     }
     LogInfo("");
     LogDebug("\nAll fragments downloaded successfully\n");
     $cc->stopDownloads();
     $this->processed = true;
 }
Ejemplo n.º 23
0
 function __construct($source, $target, $data)
 {
     require_once 'pclzip.lib.php';
     include_once '/agata/include/util.inc';
     $this->buffer = array();
     $this->break_style = '<style:style style:name="AgataPageBreak" style:family="paragraph" style:parent-style-name="Standard">' . '<style:properties fo:break-before="page"/>' . '</style:style>';
     $this->page_break = '<text:p text:style-name="AgataPageBreak"/>';
     define(temp, '/tmp');
     define("bar", '/');
     $prefix = temp . bar . RemoveExtension($source);
     $zip = new PclZip($source);
     if (($list = $zip->listContent()) == 0) {
         adie("Error : " . $zip->errorInfo(true));
     }
     recursive_remove_directory($prefix);
     if ($zip->extract(PCLZIP_OPT_PATH, $prefix) == 0) {
         adie("Error : " . $zip->errorInfo(true));
     }
     $content = file_get_contents($prefix . '/content.xml');
     # break xml tags
     $array_content = preg_split('/(<(?:[^<>]+(?:"[^"]*"|\'[^\']*\')?)+>)/', trim($content), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
     //print_r($array_content);
     $section = 'start';
     echo "antes for\n";
     foreach ($array_content as $line) {
         // <text:section text:style-name="Sect1" text:name="header">
         if (substr(trim($line), 0, 13) == '<text:section') {
             $pieces = explode('text:name="', $line);
             $section = substr($pieces[1], 0, -2);
         } else {
             if (substr(trim($line), 0, 14) == '</office:body>') {
                 $section = 'end';
             }
         }
         if ($line == '</office:automatic-styles>') {
             $line = $this->break_style . $line;
         }
         $this->buffer[$section][] = $line;
         //echo $section . "\n";
     }
     echo "depois for\n";
     print_r($this->buffer);
     $output = implode('', $this->buffer['start']);
     $break = false;
     foreach ($data as $line) {
         $sub = array();
         $sub[] = array('01/01/2005', 'abertura');
         $sub[] = array('02/01/2005', 'Software Livre');
         $sub[] = array('03/01/2005', 'PHP-GTK');
         $sub[] = array('04/01/2005', 'Agata Report');
         $sub[] = array('05/01/2005', 'encerramento');
         $sub[] = array('06/01/2005', 'encerramento2');
         $sub[] = array('07/01/2005', 'encerramento3');
         $sub[] = array('08/01/2005', 'encerramento4');
         $sub[] = array('09/01/2005', 'encerramento5');
         $sub[] = array('10/01/2005', 'encerramento6');
         $sub[] = array('11/01/2005', 'encerramento7');
         $sub[] = array('12/01/2005', 'encerramento8');
         $output .= $this->printSection('header', $line, $break);
         $output .= $this->printSection('details', $line, $sub);
         $output .= $this->printSection('footer', $line);
         //$output .= $page_break;
         $break = true;
         while ($this->rest) {
             if ($this->repeat_header) {
                 $output .= $this->printSection('header', $line, $break);
             } else {
                 $output .= $this->page_break;
             }
             $output .= $this->printSection('details', $line, $this->rest);
             if ($this->repeat_footer) {
                 $output .= $this->printSection('footer', $line);
             }
         }
     }
     $output .= implode('', $this->buffer['end']);
     echo strlen($output);
     echo "\n";
     file_put_contents($prefix . '/content.xml', $output);
     $zip2 = new PclZip($target);
     foreach ($list as $file) {
         $zip2->add($prefix . '/' . $file['filename'], PCLZIP_OPT_REMOVE_PATH, $prefix);
         echo "Adding " . $file['filename'] . "\n";
     }
 }
Ejemplo n.º 24
0
function FileUpload($resourceType, $currentFolder)
{
    $sErrorNumber = '0';
    $sFileName = '';
    if (isset($_FILES['NewFile']) && !is_null($_FILES['NewFile']['tmp_name'])) {
        $oFile = $_FILES['NewFile'];
        // Map the virtual path to the local server path.
        $sServerDir = ServerMapFolder($resourceType, $currentFolder);
        // Get the uploaded file name.
        $sFileName = $oFile['name'];
        $sOriginalFileName = $sFileName;
        $sExtension = substr($sFileName, strrpos($sFileName, '.') + 1);
        global $Config;
        $arAllowed = $Config['AllowedExtensions'][$resourceType];
        $arDenied = $Config['DeniedExtensions'][$resourceType];
        if ((count($arAllowed) == 0 || in_array($sExtension, $arAllowed)) && (count($arDenied) == 0 || !in_array($sExtension, $arDenied))) {
            $iCounter = 0;
            while (true) {
                $sFilePath = $sServerDir . $sFileName;
                if (is_file($sFilePath)) {
                    $iCounter++;
                    $sFileName = RemoveExtension($sOriginalFileName) . '(' . $iCounter . ').' . $sExtension;
                    $sErrorNumber = '201';
                } else {
                    move_uploaded_file($oFile['tmp_name'], $sFilePath);
                    if (is_file($sFilePath)) {
                        $oldumask = umask(0);
                        chmod($sFilePath, 0777);
                        umask($oldumask);
                    }
                    break;
                }
            }
        } else {
            $sErrorNumber = '202';
        }
    } else {
        $sErrorNumber = '202';
    }
    echo '<script type="text/javascript">';
    echo 'window.parent.frames["frmUpload"].OnUploadCompleted(' . $sErrorNumber . ',"' . str_replace('"', '\\"', $sFileName) . '") ;';
    echo '</script>';
    exit;
}
Ejemplo n.º 25
0
function FileUpload($resourceType, $currentFolder, $sCommand, $CKEcallback = '')
{
	if (!isset($_FILES)) {
		global $_FILES;
	}
	$sErrorNumber = '0' ;
	$sFileName = '' ;

	if ( isset( $_FILES['NewFile'] ) && !is_null( $_FILES['NewFile']['tmp_name'] )
       # This is for the QuickUpload tab box
        or (isset($_FILES['upload']) and !is_null($_FILES['upload']['tmp_name'])))
	{
		global $Config ;

		$oFile = isset($_FILES['NewFile']) ? $_FILES['NewFile'] : $_FILES['upload'];

		// Map the virtual path to the local server path.
		$sServerDir = ServerMapFolder( $resourceType, $currentFolder, $sCommand ) ;

		// Get the uploaded file name.
		$sFileName = $oFile['name'] ;
		$sFileName = SanitizeFileName( $sFileName ) ;

		$sOriginalFileName = $sFileName ;

		// Get the extension.
		$sExtension = substr( $sFileName, ( strrpos($sFileName, '.') + 1 ) ) ;
		$sExtension = strtolower( $sExtension ) ;

		if ( isset( $Config['SecureImageUploads'] ) )
		{
			if ( ( $isImageValid = IsImageValid( $oFile['tmp_name'], $sExtension ) ) === false )
			{
				$sErrorNumber = '202' ;
			}
		}

		if ( isset( $Config['HtmlExtensions'] ) )
		{
			if ( !IsHtmlExtension( $sExtension, $Config['HtmlExtensions'] ) &&
				( $detectHtml = DetectHtml( $oFile['tmp_name'] ) ) === true )
			{
				$sErrorNumber = '202' ;
			}
		}

		// Check if it is an allowed extension.
		if ( !$sErrorNumber && IsAllowedExt( $sExtension, $resourceType ) )
		{
			$iCounter = 0 ;

			while ( true )
			{
				$sFilePath = $sServerDir . $sFileName ;

				if ( is_file( $sFilePath ) )
				{
					$iCounter++ ;
					$sFileName = RemoveExtension( $sOriginalFileName ) . '(' . $iCounter . ').' . $sExtension ;
					$sErrorNumber = '201' ;
				}
				else
				{
					move_uploaded_file( $oFile['tmp_name'], $sFilePath ) ;

					if ( is_file( $sFilePath ) )
					{
						if ( isset( $Config['ChmodOnUpload'] ) && !$Config['ChmodOnUpload'] )
						{
							break ;
						}

						$permissions = 0777;

						if ( isset( $Config['ChmodOnUpload'] ) && $Config['ChmodOnUpload'] )
						{
							$permissions = $Config['ChmodOnUpload'] ;
						}

						$oldumask = umask(0) ;
						chmod( $sFilePath, $permissions ) ;
						umask( $oldumask ) ;
					}

					break ;
				}
			}

			if ( file_exists( $sFilePath ) )
			{
				//previous checks failed, try once again
				if ( isset( $isImageValid ) && $isImageValid === -1 && IsImageValid( $sFilePath, $sExtension ) === false )
				{
					@unlink( $sFilePath ) ;
					$sErrorNumber = '202' ;
				}
				else if ( isset( $detectHtml ) && $detectHtml === -1 && DetectHtml( $sFilePath ) === true )
				{
					@unlink( $sFilePath ) ;
					$sErrorNumber = '202' ;
				}
			}
		}
		else
			$sErrorNumber = '202' ;
	}
	else
		$sErrorNumber = '202' ;


	$sFileUrl = CombinePaths( GetResourceTypePath( $resourceType, $sCommand ) , $currentFolder ) ;
	$sFileUrl = CombinePaths( $sFileUrl, $sFileName ) ;


	// DOL_CHANGE
	//SendUploadResults( $sErrorNumber, $sFileUrl, $sFileName ) ;
	if($CKEcallback == '')
    {
        // this line already exists so wrap the if block around it
        SendUploadResults( $sErrorNumber, $sFileUrl, $sFileName ) ;
    }
    else
    {
    //issue the CKEditor Callback
    SendCKEditorResults ($CKEcallback, $sFileUrl,
    ($sErrorNumber != 0
      ? 'Error '. $sErrorNumber. ' upload failed. '. $sErrorMsg
      : 'Upload Successful'));
  }

	exit ;
}