Exemple #1
0
function uploadFile()
{
    global $conn_id;
    global $serverTmp;
    global $lang_server_error_up;
    global $lang_browser_error_up;
    global $filesCharSet;
    $file_name = trim($_SERVER['HTTP_X_FILENAME']);
    $path = trim($_GET["filePath"]);
    // If the $file_name or $path are garbage, the FTP server should complain
    if (isset($_SERVER['HTTP_X_FILE_SIZE'])) {
        $file_size = $_SERVER['HTTP_X_FILE_SIZE'];
    } elseif (isset($_SERVER['CONTENT_LENGTH'])) {
        $file_size = $_SERVER['CONTENT_LENGTH'];
    }
    if (empty($file_size)) {
        $file_size = 0;
    }
    // Client didn't supply a file size, continue anyhow
    if ($filesCharSet != "utf-8") {
        $file_name = iconv("utf-8", $filesCharSet, $file_name);
    }
    if ($file_name) {
        $fp1 = tempnam($serverTmp, "monsta-");
        register_shutdown_function('shutdown_unlinkTempFile', $fp1);
        // Check if a folder is being uploaded
        if ($path != "") {
            // Check to see folder path exists (and create)
            createFolderHeirarchy($path);
            $fp2 = $_SESSION["dir_current"] . "/" . $path . $file_name;
        } else {
            if ($_SESSION["dir_current"] == "/") {
                $fp2 = "/" . $file_name;
            } else {
                $fp2 = $_SESSION["dir_current"] . "/" . $file_name;
            }
        }
        // Copy the stream to a temp file
        $bytes_received = streaming_file_copy($fp1, 'php://input');
        if ($bytes_received == $file_size || $file_size == 0) {
            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);
                }
            }
        } else {
            error_log("Mismatch in file size with client (Received {$bytes_received}, client specified {$file_size}). Failing upload of {$file_name}.");
            recordFileError("file", $file_name, $lang_browser_error_up);
        }
        // Delete tmp file
        unlink($fp1);
    }
}
Exemple #2
0
function uploadFile()
{
    global $conn_id;
    global $serverTmp;
    global $lang_server_error_up;
    global $lang_browser_error_up;
    $file_name = urldecode($_SERVER['HTTP_X_FILENAME']);
    $path = $_GET["filePath"];
    if ($file_name) {
        $fp1 = tempnam($serverTmp, $file_name);
        // Check if a folder is being uploaded
        if ($path != "") {
            // Check to see folder path exists (and create)
            createFolderHeirarchy($path);
            $fp2 = $_SESSION["dir_current"] . "/" . $path . $file_name;
        } else {
            if ($_SESSION["dir_current"] == "/") {
                $fp2 = "/" . $file_name;
            } else {
                $fp2 = $_SESSION["dir_current"] . "/" . $file_name;
            }
        }
        /*
        ensureFtpConnActive();
        
        // Check if file reached server
        if (file_put_contents($fp1, file_get_contents('php://input'))) {
            
            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);
                }
            }
        } else {
            recordFileError("file", $file_name, $lang_browser_error_up);
        }
        
        // Delete tmp file
        unlink($fp1);
        */
        /* */
        $inputHandler = fopen('php://input', "r");
        $fileHandler = fopen($fp1, "w+");
        while (FALSE !== ($buffer = fgets($inputHandler, 65536))) {
            fwrite($fileHandler, $buffer);
        }
        fclose($inputHandler);
        fclose($fileHandler);
        // Check if file reached server
        if (file_exists($fp1)) {
            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);
                }
            }
        } else {
            recordFileError("file", $file_name, $lang_browser_error_up);
        }
        // Delete tmp file
        unlink($fp1);
        /* */
    }
}
Exemple #3
0
function uploadFile()
{
    global $conn_id;
    global $serverTmp;
    global $lang_server_error_up;
    global $lang_browser_error_up;
    $file_name = urldecode($_SERVER['HTTP_X_FILENAME']);
    $path = $_GET["filePath"];
    if ($file_name) {
        $fp1 = $serverTmp . "/" . $file_name;
        // Check if a folder is being uploaded
        if ($path != "") {
            // Check to see folder path exists (and create)
            createFolderHeirarchy($path);
            $fp2 = $_SESSION["dir_current"] . "/" . $path . $file_name;
        } else {
            if ($_SESSION["dir_current"] == "/") {
                $fp2 = "/" . $file_name;
            } else {
                $fp2 = $_SESSION["dir_current"] . "/" . $file_name;
            }
        }
        ensureFtpConnActive();
        // Check if file reached server
        if (file_put_contents($fp1, file_get_contents('php://input'))) {
            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);
                }
            }
        } else {
            recordFileError("file", $file_name, $lang_browser_error_up);
        }
        // Delete tmp file
        unlink($fp1);
    }
}
Exemple #4
0
function uploadFile()
{
    global $conn_id;
    global $serverTmp;
    global $lang_server_error_up;
    global $lang_browser_error_up;
    $file_name = $_SERVER['HTTP_X_FILENAME'];
    $path = $_GET["filePath"];
    if ($file_name) {
        $fp1 = $serverTmp . "/" . $file_name;
        // Check if a folder is being uploaded
        if ($path != "") {
            // Check to see folder path exists (and create)
            createFolderHeirarchy($path);
            $fp2 = $_SESSION["dir_current"] . "/" . $path . $file_name;
        } else {
            if ($_SESSION["dir_current"] == "/") {
                $fp2 = "/" . $file_name;
            } else {
                $fp2 = $_SESSION["dir_current"] . "/" . $file_name;
            }
        }
        // Check if file reached server
        if (file_put_contents($fp1, file_get_contents('php://input'))) {
            if (!@ftp_put($conn_id, $fp2, $fp1, FTP_BINARY)) {
                $_SESSION["errors"][] = str_replace("[file]", "<strong>" . $file_name . "</strong>", $lang_server_error_up);
            }
        } else {
            $_SESSION["errors"][] = str_replace("[file]", "<strong>" . $file_name . "</strong>", $lang_browser_error_up);
        }
    }
}