Пример #1
0
function net2ftp_module_printBody()
{
    // --------------
    // This function prints the upload screen
    // --------------
    // -------------------------------------------------------------------------
    // Global variables
    // -------------------------------------------------------------------------
    global $net2ftp_settings, $net2ftp_globals, $net2ftp_messages, $net2ftp_result, $net2ftp_output;
    $file_counter = 0;
    $archive_counter = 0;
    // Normal upload
    if (isset($_FILES["file"]) == true && is_array($_FILES["file"]) == true) {
        foreach ($_FILES["file"]["name"] as $key => $val) {
            if ($val != "") {
                $file_counter = $file_counter + 1;
                $uploadedFilesArray["{$file_counter}"]["name"] = validateEntry($val);
                $uploadedFilesArray["{$file_counter}"]["tmp_name"] = $_FILES["file"]["tmp_name"][$key];
                $uploadedFilesArray["{$file_counter}"]["size"] = $_FILES["file"]["size"][$key];
            }
            // end if
        }
        // end foreach
    }
    if (isset($_FILES["archive"]) == true && is_array($_FILES["archive"]) == true) {
        foreach ($_FILES["archive"]["name"] as $key => $val) {
            if ($val != "") {
                $archive_counter = $archive_counter + 1;
                $uploadedArchivesArray["{$archive_counter}"]["name"] = validateEntry($val);
                $uploadedArchivesArray["{$archive_counter}"]["tmp_name"] = $_FILES["archive"]["tmp_name"][$key];
                $uploadedArchivesArray["{$archive_counter}"]["size"] = $_FILES["archive"]["size"][$key];
            }
            // end if
        }
        // end foreach
    }
    // Upload via SWFUpload Flash applet or using the OpenLaszlo skin
    if (isset($_FILES["Filedata"]) == true && is_array($_FILES["Filedata"]) == true) {
        $file_counter = $file_counter + 1;
        $uploadedFilesArray["{$file_counter}"]["name"] = $_FILES["Filedata"]["name"];
        $uploadedFilesArray["{$file_counter}"]["tmp_name"] = $_FILES["Filedata"]["tmp_name"];
        $uploadedFilesArray["{$file_counter}"]["size"] = $_FILES["Filedata"]["size"];
    }
    // -------------------------------------------------------------------------
    // Variables for all screens
    // -------------------------------------------------------------------------
    // Title
    // The title is different for screen 1 and screen 2 - see below
    // Form name, back and forward buttons
    $formname = "UploadForm";
    $back_onclick = "document.forms['" . $formname . "'].state.value='browse';document.forms['" . $formname . "'].state2.value='main';document.forms['" . $formname . "'].submit();";
    $forward_onclick = "document.forms['" . $formname . "'].submit();";
    // Encoding type
    $enctype = "enctype=\"multipart/form-data\"";
    // Next screen
    $nextscreen = 2;
    // Maxima
    $max_filesize = $net2ftp_settings["max_filesize"];
    $max_filesize_net2ftp = $max_filesize / 1024;
    $max_upload_filesize_php = @ini_get("upload_max_filesize");
    $max_execution_time = @ini_get("max_execution_time");
    // -------------------------------------------------------------------------
    // Variables for screen 1
    // -------------------------------------------------------------------------
    if ($net2ftp_globals["screen"] == 1) {
        // Title
        $title = __("Upload files and archives");
    } elseif ($net2ftp_globals["screen"] == 2) {
        // Title
        $title = __("Upload more files and archives");
        // ---------------------------------------
        // Check the files and move them to the net2ftp temp directory
        // The .txt extension is added
        // ---------------------------------------
        if (sizeof($uploadedFilesArray) > 0 || sizeof($uploadedArchivesArray) > 0) {
            setStatus(1, 10, __("Checking files"));
            if (isset($uploadedFilesArray) == true) {
                $acceptedFilesArray = acceptFiles($uploadedFilesArray);
                if ($net2ftp_result["success"] == false) {
                    return false;
                }
            }
            if (isset($uploadedArchivesArray) == true) {
                $acceptedArchivesArray = acceptFiles($uploadedArchivesArray);
                if ($net2ftp_result["success"] == false) {
                    return false;
                }
            }
        }
        // ---------------------------------------
        // Transfer files
        // ---------------------------------------
        if (isset($acceptedFilesArray) == true && $acceptedFilesArray != "all_uploaded_files_are_too_big" && sizeof($acceptedFilesArray) > 0) {
            setStatus(0, 10, __("Transferring files to the FTP server"));
            ftp_transferfiles($acceptedFilesArray, $net2ftp_globals["directory"]);
            if ($net2ftp_result["success"] == false) {
                return false;
            }
        }
        // ---------------------------------------
        // Unzip archives and transfer the files (create subdirectories if needed)
        // ---------------------------------------
        if (isset($acceptedArchivesArray) == true && $acceptedArchivesArray != "all_uploaded_files_are_too_big" && sizeof($acceptedArchivesArray) > 0) {
            // Set the status
            setStatus(0, 10, __("Decompressing archives and transferring files"));
            // Add information to $acceptedArchivesArray
            for ($i = 1; $i <= sizeof($acceptedArchivesArray); $i = $i + 1) {
                $acceptedArchivesArray[$i]["targetdirectory"] = $net2ftp_globals["directory"];
            }
            // Unzip the archive and transfer the files
            ftp_unziptransferfiles($acceptedArchivesArray);
            if ($net2ftp_result["success"] == false) {
                return false;
            }
        }
    }
    // end elseif
    // -------------------------------------------------------------------------
    // Print the output
    // -------------------------------------------------------------------------
    if ($net2ftp_globals["skin"] == "openlaszlo") {
        require_once $net2ftp_globals["application_skinsdir"] . "/" . $net2ftp_globals["skin"] . "/manage.html.template.php";
    } else {
        require_once $net2ftp_globals["application_skinsdir"] . "/" . $net2ftp_globals["skin"] . "/manage.template.php";
    }
}
Пример #2
0
function net2ftp_module_printBody()
{
    // --------------
    // This function prints the unzip screen
    // --------------
    // -------------------------------------------------------------------------
    // Global variables
    // -------------------------------------------------------------------------
    global $net2ftp_settings, $net2ftp_globals, $net2ftp_messages, $net2ftp_result, $net2ftp_output;
    if (isset($_POST["list"]) == true) {
        $list = getSelectedEntries($_POST["list"]);
    } else {
        $list = "";
    }
    // -------------------------------------------------------------------------
    // Variables for all screens
    // -------------------------------------------------------------------------
    // Title
    $title = __("Unzip archives");
    // Form name, back and forward buttons
    $formname = "UnzipForm";
    $back_onclick = "document.forms['" . $formname . "'].state.value='browse';document.forms['" . $formname . "'].state2.value='main';document.forms['" . $formname . "'].submit();";
    $forward_onclick = "document.forms['" . $formname . "'].submit();";
    // -------------------------------------------------------------------------
    // Variables for screen 1
    // -------------------------------------------------------------------------
    if ($net2ftp_globals["screen"] == 1) {
        // Next screen
        $nextscreen = 2;
    } elseif ($net2ftp_globals["screen"] == 2) {
        $net2ftp_output["unzip"] = array();
        $net2ftp_output["ftp_unziptransferfiles"] = array();
        // ---------------------------------------
        // Initialize variables
        // ---------------------------------------
        $moved_ok = 0;
        // Index of the archives that have been treated successfully
        $moved_notok = 0;
        // Index of the archives that have been treated unsuccessfully
        // ---------------------------------------
        // Open connection to the FTP server
        // ---------------------------------------
        setStatus(2, 10, __("Connecting to the FTP server"));
        $conn_id = ftp_openconnection();
        if ($net2ftp_result["success"] == false) {
            return false;
        }
        // ---------------------------------------
        // Get the archives from the FTP server
        // ---------------------------------------
        for ($i = 1; $i <= $list["stats"]["files"]["total_number"]; $i = $i + 1) {
            // Set the status
            $message = __("Getting archive %1\$s of %2\$s from the FTP server", $i, $list["stats"]["files"]["total_number"]);
            setStatus($i, $list["stats"]["files"]["total_number"], $message);
            // Get the archive from the FTP server
            $localtargetdir = $net2ftp_globals["application_tempdir"];
            $localtargetfile = $list["files"][$i]["dirfilename"] . ".txt";
            $remotesourcedir = $net2ftp_globals["directory"];
            $remotesourcefile = $list["files"][$i]["dirfilename"];
            $ftpmode = ftpAsciiBinary($list["files"][$i]["dirfilename"]);
            $copymove = "copy";
            ftp_getfile($conn_id, $localtargetdir, $localtargetfile, $remotesourcedir, $remotesourcefile, $ftpmode, $copymove);
            if ($net2ftp_result["success"] == false) {
                setErrorVars(true, "", "", "", "");
                $net2ftp_output["unzip"][] = __("Unable to get the archive <b>%1\$s</b> from the FTP server", htmlEncode2($list["files"][$i]["dirfilename"]));
                $moved_notok = $moved_notok + 1;
                continue;
            }
            // Register the temporary file
            registerTempfile("register", glueDirectories($localtargetdir, $localtargetfile));
            // Enter the temporary filename and the real filename in the array
            $moved_ok = $moved_ok + 1;
            $acceptedArchivesArray[$moved_ok]["name"] = $list["files"][$i]["dirfilename"];
            $acceptedArchivesArray[$moved_ok]["tmp_name"] = glueDirectories($localtargetdir, $localtargetfile);
            $acceptedArchivesArray[$moved_ok]["targetdirectory"] = $list["files"][$i]["targetdirectory"];
            $acceptedArchivesArray[$moved_ok]["use_folder_names"] = $list["files"][$i]["use_folder_names"];
        }
        // end for
        // ---------------------------------------
        // Unzip archives and transfer the files (create subdirectories if needed)
        // ---------------------------------------
        if (isset($acceptedArchivesArray) == true && sizeof($acceptedArchivesArray) > 0) {
            ftp_unziptransferfiles($acceptedArchivesArray);
            $net2ftp_output["unzip"] = $net2ftp_output["unzip"] + $net2ftp_output["ftp_unziptransferfiles"];
            if ($net2ftp_result["success"] == false) {
                return false;
            }
        }
        // ---------------------------------------
        // Close the connection to the FTP server
        // ---------------------------------------
        ftp_closeconnection($conn_id);
    }
    // end elseif
    // -------------------------------------------------------------------------
    // Print the output
    // -------------------------------------------------------------------------
    require_once $net2ftp_globals["application_skinsdir"] . "/" . $net2ftp_globals["skin"] . "/manage.template.php";
}