1

我正在尝试从 HTML 表单上传一个 zip 文件和一个 csv 文件。

在 PHP 上,当我打印 $_FILES(实际上是 symfony 中的 $request->getFiles())时,我得到了关注。

Array
(
    [zipfile] => Array
        (
            [name] => tempfiles.zip
            [type] => application/octet-stream
            [tmp_name] => C:\wamp\tmp\php5D42.tmp
            [error] => 0
            [size] => 850953
        )
    [csvfile] => Array
        (
            [name] => test.csv
            [type] => application/vnd.ms-excel
            [tmp_name] => C:\wamp\tmp\php5D52.tmp
            [error] => 0
            [size] => 312
        )
)

我想知道typeand tmp_name。我需要根据类型做出一些决定。对现有类型做出决定是否安全?对于 Linux 服务器上的类似文件,我会得到相同的结果吗?

再次tmp_name.tmp扩展。它在 Windows/Linux 上是否一致?如果没有,有什么方法可以让我在 Windows 上编写的代码(使用决定type)在 linux 上运行没有任何问题?

4

2 回答 2

3

使用它type可能很危险,因为用户可以更改文件的类型并可以上传 php 脚本。

您应该typeget_image_size()一样验证第一个来验证图像文件。我不知道 .zip 文件

于 2012-09-25T09:47:34.103 回答
2

type信任表单是不安全的$_FILES,您需要在服务器端验证文件类型。

对于.tmp扩展,在 windows 或 linux 上都可以。

于 2012-09-25T09:42:57.530 回答