使用php发送文件,不使用POST,但使用type=file


Send file with php without POST but in use with type=file

我遇到了这样的问题,我必须在浏览器中创建文件发送系统,但对于大文件(>50M)。我有POST_MAX_SIZE set at 32M but FILE_MAX_SIZE is 128M。所以我必须把类型文件按钮和读取完整的路径发送给PHP FTP库。你有什么解决方案吗?(filetype.value returns only filename, not path)。

是,

使用HTML5中定义的FileReader将文件读入客户端。一旦您通过Ajax将其发送到您的服务器,在那里您可以完全访问文件,因为它在服务器上。

根据这篇SO文章,你可以在服务器上设置接受的最大文件大小。

; Maximum allowed size for uploaded files.
upload_max_filesize = 40M
; Must be greater than or equal to upload_max_filesize
post_max_size = 40M

您可以在php.ini文件"upload_max_filesize=256"中增加文件大小,然后重新启动apache服务器

upload_max_filesizepost_max_size是PHP_INI_PERDIR设置-http://www.php.net/manual/en/ini.list.php.它们是可变的(http://php.net/manual/en/configuration.changes.modes.php)-

条目可以在php.ini、.htaccess、httpd.conf或.user.ini(自php 5.3起)中设置

使用网络托管根目录中的.user.ini文件(大多数网络托管服务都允许这样做)。如果你的服务器PHP版本是>=PHP 5.3,它就会工作。PHP将扫描您的根目录中的ini文件,并将其与默认设置合并。

我最近使用了它,并将upload_max_filesize的默认值从2M更改为5M,以满足我个人的需求。它可能对你也有用。创建一个名为.user.ini的文件,并将参数设置为:

post_max_size = ...
upload_max_filesize = ...

请记住,post_max_size应该大于upload_max_filesize,因为前者是post的上限。