Пример #1
0
function renameFiles()
{
    global $conn_id;
    global $lang_file_exists;
    global $lang_folder_exists;
    global $lang_cant_rename;
    global $lang_title_rename;
    // Check for processing of form
    if (!empty($_POST["processAction"]) && $_POST["processAction"] == 1) {
        $i = 0;
        // Go through array of saved names
        foreach ($_SESSION["clipboard_rename"] as $file) {
            $isError = 0;
            $file_name = trim($_POST["file" . $i]);
            $file_name = quotesUnescape($file_name);
            $file = quotesUnescape($file);
            $fileExists = 0;
            // Check for a different name
            if ($file_name != $file) {
                if ($_SESSION["dir_current"] == "/") {
                    $file_to_move = "/" . $file;
                }
                if ($_SESSION["dir_current"] == "~") {
                    $file_to_move = "~/" . $file;
                }
                if ($_SESSION["dir_current"] != "/" && $_SESSION["dir_current"] != "~") {
                    $file_to_move = $_SESSION["dir_current"] . "/" . $file;
                }
                $file_destination = $_SESSION["dir_current"] . "/" . $file_name;
                // Check if file exists
                if (checkFileExists("f", $file_name, $_SESSION["dir_current"]) == 1) {
                    recordFileError("file", sanitizeStr($file_name), $lang_file_exists);
                    $fileExists = 1;
                }
                // Check if folder exists
                if (checkFileExists("d", $file_name, $_SESSION["dir_current"]) == 1) {
                    recordFileError("folder", sanitizeStr($file_name), $lang_folder_exists);
                    $fileExists = 1;
                }
                if ($fileExists == 0) {
                    if (!@ftp_rename($conn_id, $file_to_move, $file_destination)) {
                        if (checkFirstCharTilde($file_to_move) == 1) {
                            if (!@ftp_rename($conn_id, replaceTilde($file_to_move), replaceTilde($file_destination))) {
                                recordFileError("file", sanitizeStr($file), $lang_cant_rename);
                                $isError = 1;
                            }
                        } else {
                            recordFileError("file", sanitizeStr($file), $lang_cant_rename);
                            $isError = 1;
                        }
                    }
                    if ($isError == 0) {
                        // Delete item from history
                        deleteFtpHistory($file_to_move);
                    }
                }
            }
            $i++;
        }
        // Reset var
        $_SESSION["clipboard_rename"] = array();
    } else {
        // Recreate arrays
        $fileArray = recreateFileFolderArrays("file");
        $folderArray = recreateFileFolderArrays("folder");
        $_SESSION["clipboard_rename"] = array();
        $n = sizeof($fileArray) + sizeof($folderArray);
        $height = $n * 35;
        $width = 565;
        $title = $lang_title_rename;
        displayPopupOpen(1, $width, $height, 0, $title);
        $i = 0;
        // Set vars
        $vars = "&ftpAction=rename&processAction=1";
        $onKeyPress = "onkeypress=\"if (event.keyCode == 13){ processForm('" . $vars . "'); activateActionButtons(0,0); return false; }\"";
        // Display folders
        foreach ($folderArray as $folder) {
            $folder = getFileFromPath($folder);
            echo "<img src=\"images/icon_16_folder.gif\" width=\"16\" height=\"16\"> ";
            echo "<input type=\"text\" name=\"file" . $i . "\" class=\"inputRename\" value=\"" . quotesReplace($folder, "d") . "\" " . $onKeyPress . "><br>";
            $_SESSION["clipboard_rename"][] = $folder;
            $i++;
        }
        // Display files
        foreach ($fileArray as $file) {
            $file = getFileFromPath($file);
            echo "<img src=\"images/icon_16_file.gif\" width=\"16\" height=\"16\"> ";
            echo "<input type=\"text\" name=\"file" . $i . "\" class=\"inputRename\" value=\"" . quotesReplace($file, "d") . "\" " . $onKeyPress . "><br>";
            $_SESSION["clipboard_rename"][] = $file;
            $i++;
        }
        displayPopupClose(0, $vars, 1);
    }
}
Пример #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);
        }
    }
}