Пример #1
0
function tidyFolderPath($str1, $str2)
{
    $str1 = replaceTilde($str1);
    if ($str1 == "/") {
        return "/" . $str2;
    } else {
        return $str1 . "/" . $str2;
    }
}
Пример #2
0
function fetchFile()
{
    global $conn_id;
    global $serverTmp;
    global $lang_server_error_up;
    global $lang_title_fetch_file;
    global $lang_fetch_no_file;
    global $lang_fetch_not_found;
    global $lang_btn_fetch;
    $height = 40;
    $width = 565;
    $title = $lang_title_fetch_file;
    if (!function_exists("file_get_contents")) {
        recordFileError("", "", "PHP function <i>file_get_contents</i> not supported on this server.");
    } else {
        // Check for processing of form
        if ($_POST["processAction"] == 1) {
            $fetch_url = trim($_POST["fetch_url"]);
            // Check remote file exists
            $headers = get_headers($fetch_url);
            if (!preg_match("/\\./", basename($fetch_url))) {
                recordFileError("", "", $lang_fetch_no_file);
            } else {
                if (!preg_match("/200 OK/", $headers[0])) {
                    recordFileError("", "", $lang_fetch_not_found);
                } else {
                    // Set file paths
                    $file_name = basename($fetch_url);
                    $fp1 = tempnam($serverTmp, $file_name);
                    if ($_SESSION["dir_current"] == "/") {
                        $fp2 = "/" . $file_name;
                    } else {
                        $fp2 = $_SESSION["dir_current"] . "/" . $file_name;
                    }
                    // Fetch the file
                    $inputHandler = fopen($fetch_url, "r");
                    $fileHandler = fopen($fp1, "w+");
                    while (FALSE !== ($buffer = fgets($inputHandler, 65536))) {
                        fwrite($fileHandler, $buffer);
                    }
                    fclose($inputHandler);
                    fclose($fileHandler);
                    ensureFtpConnActive();
                    if (!@ftp_put($conn_id, $fp2, $fp1, FTP_BINARY)) {
                        if (checkFirstCharTilde($fp2) == 1) {
                            if (!@ftp_put($conn_id, replaceTilde($fp2), $fp1, FTP_BINARY)) {
                                recordFileError("file", $file_name, $lang_server_error_up);
                            }
                        } else {
                            recordFileError("file", $file_name, $lang_server_error_up);
                        }
                    }
                    // Delete tmp file
                    unlink($fp1);
                }
            }
        } else {
            $vars = "&ftpAction=fetchFile&processAction=1";
            $onKeyPress = "onkeypress=\"if (event.keyCode == 13){ processForm('" . $vars . "'); return false; }\"";
            displayPopupOpen(1, $width, $height, 0, $title);
            echo "<div class=\"floatLeft10\">";
            echo "<input type=\"text\" name=\"fetch_url\" class=\"inputFetch\" value=\"" . quotesReplace($folder, "d") . "\" " . $onKeyPress . " placeholder=\"http://...\"> ";
            echo "</div>";
            echo "<div id=\"ajaxWaiting\" class=\"floatLeft10\">";
            echo "<input type=\"button\" class=\"popUpBtnNoMargin\" value=\"" . $lang_btn_fetch . "\" onClick=\"processForm('" . $vars . "');\" class=\"";
            echo adjustButtonWidth($lang_btn_fetch);
            echo "\"> ";
            echo "</div>";
            displayPopupClose(0, "", 1);
        }
    }
}