简体   繁体   English

php上传$ _FILES [FileName] [“ tmp_name”]唯一性

[英]php uploads $_FILES[FileName][“tmp_name”] uniqueness

I can't find specific information as to the uniqueness of $_FILES["FileName"]["tmp_name"] . 我找不到有关$_FILES["FileName"]["tmp_name"]的唯一性的特定信息。

From: http://php.net/manual/en/reserved.variables.files.php I see that 6 hex characters are what make the file name unique. 来自: http : //php.net/manual/en/reserved.variables.files.php我看到6个十六进制字符是使文件名唯一的原因。 eg /tmp/php/php6hst32 例如/tmp/php/php6hst32

From local testing ( XAMPP | WIN 7 ) I see only 4 hex characters eg \\tmp\\phpCC07.tmp 从本地测试( XAMPP | WIN 7 ),我只能看到4个十六进制字符,例如\\tmp\\phpCC07.tmp

This would suggest a min uniqueness of 1 in 65536 which doesn't seem that unique to me. 这表明65536的最小唯一性为1 ,这对我而言似乎并不是唯一的。

Where is this set within PHP? PHP中此设置在哪里? (it's not in php.ini ). (它不在php.ini )。 Is it hard coded or can it be configured? 它是硬编码的还是可以配置的?

I realise that a clash could only happen within a brief period since the file should last only the duration of the script but these odds don't offer the comfort I was expecting. 我意识到冲突只能在很短的时间内发生,因为文件只能持续脚本的持续时间,但是这些几率并不能提供我所期望的舒适性。

The files are guaranteed to be unique. 这些文件保证是唯一的。 PHP uses GetTempFileName() on Windows and mkstemp() or mktemp() on Linux. PHP在Windows上使用GetTempFileName() mktemp()在Linux上使用mkstemp()mktemp()

GetTempFileName() produces filenames of the format <prefix>XXXX. GetTempFileName()生成格式为<prefix> XXXX的文件名。 (This is what you see with XAMPP) (这就是您使用XAMPP看到的内容)

mkstemp() and mktemp() produce filenames of the format <prefix>XXXXXX. mkstemp()mktemp()产生格式为<prefix> XXXXXX的文件名。 (This is what was in the docs) (这就是文档中的内容)

These are not configurable, they are set by the system's standard C library. 这些是不可配置的,它们是由系统的标准C库设置的。 The system guarantees that the filenames that are generated are unique. 系统保证生成的文件名是唯一的。 If the system is unable to create a unique filename, the function call returns an error status to PHP which in turn raises an E_WARNING : "File upload error - unable to create a temporary file". 如果系统无法创建唯一的文件名,则函数调用将向PHP返回错误状态,从而引发E_WARNING :“文件上传错误-无法创建临时文件”。

References: 参考文献:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM