如何在本地服务器上上传Image

时间:2016-06-29 18:01:44

标签: php

经过80次以上(同时使用本网站的所有提示)没有结果。 (我在Debian Server和windows 10上工作) 我在互联网上做,但不在本地服务器上 我的代码是:

<html>
<head>
<meta charset="utf-8">
</head>
<body>            
<form action="upload_OneImage.php" method="post" enctype="multipart/form-data">
<input type="file" name="photoU" /><br />
<input type="submit" name="submit" value="Upload" />
</form>
<?php
$valid_file = NULL;
if (isset($_POST['submit'])) {
    //if they DID upload a file...
    if ($_FILES['photoU']['name']) {
        //if no errors...
        if (!$_FILES['photoU']['error']) {
            //check the size of file and validate it's size
            $new_file_name = strtolower($_FILES['photoU']['name']);
            //change the all the capital letter to lower letter
            echo "file_name= $new_file_name <br />";
            if ($_FILES['photoU']['size'] > (1024000)) { //can't be larger than 1 MB
                $valid_file = FALSE;
                $message    = "Oops!  Your file's size is too large.";
            } else {
                $valid_file = TRUE;
            }
            //if the test was successfull
            if ($valid_file) {
                //move it to directory that name "upload"
                move_uploaded_file($_FILES["file"]["tmp_name"][0], "upload/" . $_FILES["file"]["name"][0]);
                //move_uploaded_file($_FILES['photoU']['tmp_name'], 'upload/' . $new_file_name);
                $message = 'Congratulations!  Your file was accepted.<br />';
            }
        }
        //if there is an error...
        else {
            //set that to be the returned message
            $message = 'Sorry!  Your upload triggered the following error:  ' . $_FILES['photoU']['error'];
        }
    }
    echo "$message ";
}
?>

</body>
</html>

我有一个目录为“images”。它包含imges。我有另一个目录作为“上传”来保存上传文件。 我还希望在上传时以小尺寸显示图像。 有人能告诉我什么是问题吗?

0 个答案:

没有答案