为什么文件上传不能在php中工作?

时间:2016-05-31 18:54:59

标签: php file file-upload file-handling

你好我有一个简单的PHP表单,它有一个输入文件字段和上传按钮我想要做的是当点击按钮时文件应该上传到一个名为uploads的目录但是它不会在这里工作是代码。

<?php
if(isset($_FILES['uploadfilefield']))
{
    $uploadName = $_FILES['uploadfilefield']['name'];
    $uploadTmp = $_FILES['uploadfilefield']['tmp_name'];
    $uploadType = $_FILES['uploadfilefield']['type'];

    $uploadName = preg_replace("#[^a-z0-9.]#i","",$uploadName);

    if(!$uploadTmp)
    {
        die("no file Selected,Please Upload Again");
    }
    else
    {
        move_uploaded_file($uploadTmp, "uploads/$uploadName");
    }
}
?>


<!DOCTYPE html>
<html>
<head>
    <title>File Upload</title>

    <style>
        body
        {
            margin: 0;
            padding: 0;
            background: #CCC;
        }
        .fileuploadholder
        {
            width : 400px;
            height: 200px;
            margin: 60px auto 0px auto;
            border: 1px solid #CCC;
            background: #FFF;
            padding: 20px;
            box-sizing: border-box;
        }
    </style>
</head>
<body>

    <div class="fileuploadholder">
        <form method="post" enctype="multipart/form-data" action="index.php">
            <input type="file" name="fileupload" id="uploadfilefield">
            <input type="submit" value="Upload" id="uploadbutton">
        </form>
    </div>
</body>
</html>

这是我的目录enter image description here

的照片

,这是在目录

enter image description here

0 个答案:

没有答案