Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么不是';t upload.php是否将文件上载到目录?_Php_Html - Fatal编程技术网

为什么不是';t upload.php是否将文件上载到目录?

为什么不是';t upload.php是否将文件上载到目录?,php,html,Php,Html,非常感谢您花时间阅读并回答,我们有一个php文件,它可以执行,它将url打印为index.php?uploady,就像我们在头部分编写代码时标记的那样。它似乎执行得很好。唯一的问题,也是一个非常大的问题是,它没有将文件从文件目标变量放置到服务器文件夹中,它似乎没有将本地文件放置在服务器中的任何位置。我们的代码如下: <form action="upload.php" method="POST" enctype="multipart/form-data"> <in

非常感谢您花时间阅读并回答,我们有一个php文件,它可以执行,它将url打印为index.php?uploady,就像我们在头部分编写代码时标记的那样。它似乎执行得很好。唯一的问题,也是一个非常大的问题是,它没有将文件从文件目标变量放置到服务器文件夹中,它似乎没有将本地文件放置在服务器中的任何位置。我们的代码如下:

<form action="upload.php" method="POST" enctype="multipart/form-data">
        <input type="file" name="file">
        <button type="submit" name="submit">
            UPLOAD
        </button>
    </form>

<?php 
ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);
if (isset($_POST['submit'])) {
    $file = $_FILES['file'];

    $fileName = $_FILES['file']['name'];
    $fileTmpName = $_FILES['file']['tmp_name'];
    $fileSize = $_FILES['file']['size'];
    $fileError = $_FILES['file']['error'];
    $fileType = $_FILES['file']['type'];

    $fileExt = explode('.', $fileName);
    $fileActualExt = strtolower(end($fileExt));

    $allowed = array('jpg', 'jpeg', 'png', 'gif');

    if (in_array($fileActualExt, $allowed)) {
        if ($fileError === 0) {
            if ($fileSize < 200000000) {
                $fileNameNew = uniqid('', true).".".$fileActualExt;
                $fileDestination = '/public_html/styleuploads'.$fileNameNew;
                move_uploaded_file($fileTmpName, $fileDestination);
                header("Location: index.php?uploadyay");
                exit;
            } else echo "Opps, your file is too big! It needs to be smaller than 200 Megabytes";
        } else {
            echo "There was an error uploading your file";
        }
    } else {
        echo "You can not upload files of that type";
    }
}
?>

上传
请检查下面的代码

上传

您需要检查目标目录权限,确保它是可写的。检查$fileDestination是否为绝对路径(我对此表示怀疑),并检查目标目录中的权限。这是可行的,但它不会进入正确的文件夹。在我看来,这是一个小得多的问题。因此,我现在实际上正在服务器中获取上传的文件,只是为了与目的地一起玩
<form action="upload.php" method="POST" enctype="multipart/form-data">
        <input type="file" name="file">
        <button type="submit" name="submit">
            UPLOAD
        </button>
    </form>

<?php 
ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);
if (isset($_POST['submit'])) {
    $file = $_FILES['file'];

    $fileName = $_FILES['file']['name'];
    $fileTmpName = $_FILES['file']['tmp_name'];
    $fileSize = $_FILES['file']['size'];
    $fileError = $_FILES['file']['error'];
    $fileType = $_FILES['file']['type'];

    $fileExt = explode('.', $fileName);
    $fileActualExt = strtolower(end($fileExt));

    $allowed = array('jpg', 'jpeg', 'png', 'gif');

    if (in_array($fileActualExt, $allowed)) {
        if ($fileError === 0) {
            if ($fileSize < 200000000) {
                $fileNameNew = uniqid('', true).".".$fileActualExt;
                $fileDestination = $_SERVER['DOCUMENT_ROOT'].'/public_html/';
                $moved = move_uploaded_file($fileTmpName, $fileDestination.'styleuploads'.$fileNameNew);
                header("Location: index.php?uploadyay");
                exit;
            } else echo "Opps, your file is too big! It needs to be smaller than 200 Megabytes";
        } else {
            echo "There was an error uploading your file";
        }
    } else {
        echo "You can not upload files of that type";
    }
}
?>