Php 无法移动上载的文件

Php 无法移动上载的文件,php,linux,web,backend,Php,Linux,Web,Backend,我一直在试图上传一个文件到我的网站。该名称存储在我的数据库中。我尝试了各种路径符号: ../images/products,images/products,/var/www/html/images/products 但似乎都不管用。是的,它是与POST一起提交的。我一直在想,也许PHP没有写入该位置的权限 在这里您可以看到我的代码: $imageName = $image['name']; $imageTmp = $image['tmp_name']; $imgS

我一直在试图上传一个文件到我的网站。该名称存储在我的数据库中。我尝试了各种路径符号:

../images/products,images/products,/var/www/html/images/products

但似乎都不管用。是的,它是与POST一起提交的。我一直在想,也许PHP没有写入该位置的权限

在这里您可以看到我的代码:

$imageName = $image['name'];
        $imageTmp = $image['tmp_name'];
        $imgSize = $image['size'];
        $imgError = $image['error'];

        $imgExt = explode('.',$imageName);
        $imgActualExt = strtolower(end($imgExt));

        $allowedExt = array('jpg', 'jpeg', 'png');

        if(in_array($imgActualExt, $allowedExt))
        {
            if($imgError === 0)
            {
                if($imgSize <= 5000000) #If imgSize is smaller then or equal to 5MB
                {
                    $imageNewName = uniqid('', true) . "." . $imgActualExt;
                    $imageDest = "../images/products/" . $imageNewName;
                    if(move_uploaded_file($imageTmp,$imageDest))
                    {
                        $sql = "INSERT INTO Products (name, stock, price, image_name) VALUES (?, ?, ?, ?)";
                        $stmt = mysqli_stmt_init($conn);
                        if(!mysqli_stmt_prepare($stmt, $sql))
                        {
                            header("Location: ../dashboard.php?error=sqlerror1");
                        }
                        else
                        {
                            mysqli_stmt_bind_param($stmt, "ssss", $name, $stock, $price, $imageNewName);
                            mysqli_stmt_execute($stmt);
                            header("Location: ../dashboard.php?successWithImage=".$imageTmp);
                        }
                    }
                    else
                    {
                        header("Location: ../dashboard.php?error=CouldNotMove");
                    }
                }
                else
                {
                    header("Location: ../dashboard.php?error=Size=".$imgSize);
                }
            }
            else
            {
                header("Location: ../dashboard.php?error=Error:" . $imgError);
            }
        }
        else
        {
            header("Location: ../dashboard.php?error=FileTypeNotAllowed");
        }
$imageName=$image['name'];
$imageTmp=$image['tmp_name'];
$imgSize=$image['size'];
$imgError=$image['error'];
$imgExt=分解('.',$imageName);
$imgActualExt=strtolower(end($imgExt));
$allowedExt=array('jpg','jpeg','png');
if(在数组中($imgactualest,$allowedExt))
{
如果($imgError==0)
{

如果($imgSize,请尝试创建目录并检查权限。 试试这个


尝试创建目录并检查权限。 试试这个


使用文件的完整路径和目标进行测试我会尝试,谢谢!使用文件的完整路径和目标进行测试我会尝试,谢谢!首先,您的代码在这里有一个目录遍历安全漏洞。其次,使用mime_content_type检查文件扩展名,不信任用户输入。我看不出任何问题,为什么创建日志时这不起作用让我们看看发生了什么wrong@VitaliProtosovitski感谢您提供的信息!首先,您的代码存在目录遍历安全漏洞。其次,请使用mime_content_type检查文件扩展名,不要信任用户输入。我看不出任何问题,为什么这不起作用?创建日志,只需检查发生了什么wrong@VitaliPro托索维茨基感谢您提供的信息!
$imageNewName = uniqid('', true) . "." . $imgActualExt;
/////////
mkdir("hi");
$imageDest = "hi/" . $imageNewName;
/////////
if(move_uploaded_file($imageTmp,$imageDest))