簡體   English   中英

無法使用 PHP 將圖像文件上傳到具有 IIS 的網絡服務器

[英]Can't upload image file to webserver with IIS using PHP

我在 PHP 中編寫了一個小代碼,以將圖像文件上傳到我們在 windows 高級服務器 2016 上運行的網絡服務器中,並帶有 IIS。 我的意思是我只是復制粘貼示例代碼來上傳文件。 代碼運行沒有錯誤,但無法保存所選文件。

<html>
    <head>
    <Title>Covid-19 Heatmap Image Upload</Title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css">
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css"></script>
    </head>
    <body>
        <H5>Covid-19 Heatmap Image Upload</H5>

        <?php
            if (isset($_FILES['userfile'])){

                //pre_r($_FILES);

                $phpFileUploadErrors = array(
                0 => 'There is no error, the file uploaded with success.',
                1 => 'The uploaded file exceeds the upload_max_filesize directive in php.ini.',
                2 => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.',
                3 => 'The uploaded file was only partially uploaded.',
                4 => 'No file was uploaded.',
                6 => 'Missing a temporary folder.',
                7 => 'Failed to write file to disk.',
                8 => 'A PHP extension stopped the file upload.',
                );
                
                $ext_error = false;
                // uploadable extension allowed
                $extensions = array('jpg', 'jpeg', 'gif', 'png');
                $file_ext = explode('.', $_FILES['userfile']['name']);
                $file_ext = end($file_ext);

                if (!in_array($file_ext, $extensions)){
                    $ext_error = true;
                }

                // if the error of the upload is not 0 then there is error
                if ($_FILES['userfile']['error']){ 
                    echo $phpFileUploadErrors[$_FILES['userfile']['ERROR']];
                }
                elseif ($ext_error){
                    echo "Invalid file extension!";
                }
                else {
                    move_uploaded_file($_FILES['userfile']['tmp_name'], './heatmap/'.
                    $_FILES['userfile']['name']);
                    echo "Success! Image has been uploaded.";
                }               
            }
            function pre_r($array){
                echo '<pre>';
                print_r($array);
                echo '</pre>';
            }
        ?>
        <form action="" method="POST" enctype="multipart/form-data">
            <input type="file" name="userfile" />
            <input type="submit" value="Upload" />
        </form>
    </body>
</html>

是否有任何看不見的錯誤,或者可能沒有。 我的路徑是 c:/inetpub/winroot/heatmap。

你的代碼沒有問題。 您只需要更改一件事,即您的文件上傳位置。

move_uploaded_file($_FILES['userfile']['tmp_name'], './heatmap/'.

move_uploaded_file($_FILES['userfile']['tmp_name'], './'.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM