PHP文件上传,但可以';在目录中找不到


PHP file uploading but can't find in directory

我在stackoverflow上检查了几个方法,但没有一个能够解决这个问题。我制作了一个html表单,通过SELF_PHP表单输入文件类型。PHP似乎正确上传了文件,但上传到的目录是空的。这是代码:HTML

<form method="post" id="fileUpForm" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" enctype="multipart/form-data" >
    Select image to upload: 
    <input type="file" name="fileToUpload" id="fileToUpload">
    <input type="submit" value="Upload" name="submit">
</form>

PHP

<?php 
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
    $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
    if($check !== false) {
        echo "File is an image - " . $check["mime"] . ".";
        $uploadOk = 1;
    } else {
        echo "File is not an image.";
        $uploadOk = 0;
    }
}
 ?> 

附加信息:.php文件目录-/var/www/html/FileUp.php
上传目录(用于存储文件)-/var/www/html/uploads/代码使用(修改)自:'*schools.com'

我看不到您的文件有任何"移动"。你已经把它上传到临时内存中,现在你必须随时移动它。

使用PHP:move_uploaded_file

<?php 
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
    $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
    if($check !== false) {
        // if check is ok, move the file to the target directory
        move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_dir)
        echo "File is an image - " . $check["mime"] . ".";
        $uploadOk = 1;
    } else {
        echo "File is not an image.";
        $uploadOk = 0;
    }
}
?>