Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/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
Php $\u文件不是空的,但文件没有';t上传_Php_File - Fatal编程技术网

Php $\u文件不是空的,但文件没有';t上传

Php $\u文件不是空的,但文件没有';t上传,php,file,Php,File,我有一个上传文件的表格,检查文件是否到达的代码在这里: if (is_uploaded_file($_FILES['foto'] ['tmp_name'])){ echo "file is valid and was uploaded"; print_r($_FILES); } 上面写着: file is valid and was uploadedArray ( [foto] => Array ( [name] => Penguins.jpg [typ

我有一个上传文件的表格,检查文件是否到达的代码在这里:

if (is_uploaded_file($_FILES['foto'] ['tmp_name'])){
   echo "file is valid and was uploaded";
   print_r($_FILES);
 }
上面写着:

 file is valid and was uploadedArray ( [foto] => 
 Array ( [name] => Penguins.jpg     [type] => image/jpeg [tmp_name]   
 => /var/www/uploads/phpf8ECTX [error] => 0 [size] => 777835 ) ) 
 Array ( [foto] => Array ( [name] => Penguins.jpg [type] => image/jpeg [tmp_name] 
=> /var/www/uploads/phpf8ECTX [error] => 0 [size] => 777835 ) ) array(1) { 
["foto"]=> array(5) { ["name"]=> string(12) "Penguins.jpg" ["type"]=> string
(10) "image/jpeg" ["tmp_name"]=> string(26) "/var/www/uploads/phpf8ECTX" ["error"]
=> int(0) ["size"]=> int(777835) } } 
但是文件没有到达,php.ini配置正确,/var/www/uploads目录对所有用户都有写的权限,我在linux中运行apache2,知道怎么回事吗?
谢谢

完成后,您必须
将上传的文件
移动到上传目录。我的理解是,如果您没有明确地将文件持久化到另一个文件夹,PHP将上载到一个临时文件夹,然后将其删除

if (is_uploaded_file($_FILES['foto'] ['tmp_name'])){
    if (file_exists("upload/" . $_FILES["foto"]["name"]))
    {
        //Maybe you want to issue an error message if the file already exists, like this.
        echo $_FILES["foto"]["name"] . " already exists. ";
    }
    else
    {
        move_uploaded_file($_FILES["foto"]["tmp_name"],
            "upload/" . $_FILES["foto"]["name"]);
    }
}

并记住为上传设置一个不同的临时目录。

一旦上传完成,您必须
将上传的文件移动到上传目录。我的理解是,如果您没有明确地将文件持久化到另一个文件夹,PHP将上载到一个临时文件夹,然后将其删除

if (is_uploaded_file($_FILES['foto'] ['tmp_name'])){
    if (file_exists("upload/" . $_FILES["foto"]["name"]))
    {
        //Maybe you want to issue an error message if the file already exists, like this.
        echo $_FILES["foto"]["name"] . " already exists. ";
    }
    else
    {
        move_uploaded_file($_FILES["foto"]["tmp_name"],
            "upload/" . $_FILES["foto"]["name"]);
    }
}
请记住为您的上载设置不同的临时目录。

is_uploaded_file()仅确认您引用的文件实际上是上载文件还是系统文件,例如/etc/passwd。您可以在此处阅读更多信息:

如果通过HTTP POST上载了按文件名命名的文件,则返回TRUE。 这有助于确保恶意用户没有尝试 诱使脚本处理不应在其上运行的文件 正在工作——例如,/etc/passwd

如果有任何可能 对上传的文件所做的任何操作都可能会将其内容泄露给用户 用户,甚至是同一系统上的其他用户

验证文件名和属性(根据您的具体要求)后,必须调用move_uploaded_file()将文件从临时位置移动到永久主位置

以下是实际上载脚本的一个很好的示例:


is_uploaded_file()仅确认您所引用的文件是否确实是上载文件,而不是系统文件,例如/etc/passwd。您可以在此处阅读更多信息:

如果通过HTTP POST上载了按文件名命名的文件,则返回TRUE。 这有助于确保恶意用户没有尝试 诱使脚本处理不应在其上运行的文件 正在工作——例如,/etc/passwd

如果有任何可能 对上传的文件所做的任何操作都可能会将其内容泄露给用户 用户,甚至是同一系统上的其他用户

验证文件名和属性(根据您的具体要求)后,必须调用move_uploaded_file()将文件从临时位置移动到永久主位置

以下是实际上载脚本的一个很好的示例:



检查
是否上载文件()
是冗余的-它包含在
移动\u上载文件()
中。检查
是否上载文件()
是冗余的-它包含在
移动\u上载文件()
中。