如何处理 PHP 请求中的长标头声明?

发布于 2024-10-07 01:55:52 字数 963 浏览 0 评论 0原文

我正在尝试使用 Picasa Web Uploader API 上传图库照片到我的网站。我已经能够实现该按钮,在 Picasa 中对其进行设置并进行身份验证,但在处理我的网站从 Picasa 收到的 POST 时,$_FILES 数组始终为空。

我使用 Fiddler 查看了 Picasa 发布的请求,并且能够识别出每个文件多部分开头的 Content-Disposition 标头是 太长 - Picasa 发送的标头包含完整路径我的服务器上的文件,所以它最终远远超过 128 个字符:

Content-Disposition: form-data; name="http://localhost:50216/1f6b3b29edc6f9d8898ede07c1b10e27/image/415603f72f75af1a.jpg?size=640"; filename="DSC_0055.JPG"

似乎 PHP 只能处理最多 128 个字符的标头,并且如果标头太长,整个多部分部分将被丢弃。 (当我在 Fiddler 中减少此标头的长度并重新发布请求时,我的网站收到 $_FILE 并成功处理它)。

如何解决这个问题?

  • 我可以在某处设置配置设置以允许 PHP 处理长标头并接收 $_FILE 数组中的数据吗?
  • 或者,除了 $_FILE 数组之外,我可以通过其他方式访问丢失的多部分部分吗?

I'm trying to use the Picasa Web Uploader API to upload galleries of photos to my website. I've been able to implement the button, get it set up in Picasa and get authentication working, but when it comes to processing the POST received by my site from Picasa the $_FILES array is always empty.

I've had a look at the request posted by Picasa using Fiddler, and have been able to identify that the Content-Disposition header at the start of each file multipart is too long - the header sent through by Picasa includes the full path to the file on my server, so it ends up being far more than 128 characters:

Content-Disposition: form-data; name="http://localhost:50216/1f6b3b29edc6f9d8898ede07c1b10e27/image/415603f72f75af1a.jpg?size=640"; filename="DSC_0055.JPG"

It seems that PHP can only handle headers up to 128 characters, and that the whole multi-part section is discarded if the header is too long. (When I reduce the length of this header in Fiddler and re-post the request, my website receives the $_FILE and handles it successfully).

How can I work around this?

  • Can I set a configuration setting somewhere to allow PHP to handle the long header and receive the data in the $_FILE array?
  • or, can I access the missing multi-part section in some other way, besides the $_FILE array?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

送舟行 2024-10-14 01:55:53

如果您确实需要访问原始传入 HTTP 主体,那么您可以使用 http_get_request_body() 如果你安装了 PECL 模块,如果没有,那么有一个流包装器我相信:

$httpBody = @file_get_contents('php://input');

虽然远非理想,但我不知道 $_FILES 有这个问题,需要注意的事情。

Well if you really need access to the raw incoming HTTP body, then you can use http_get_request_body() if you have PECL module installed, if not then there is a stream wrapper I believe:

$httpBody = @file_get_contents('php://input');

Far from ideal though, I was unaware $_FILES had this problem, something to look out for.

网名女生简单气质 2024-10-14 01:55:52

你完蛋了。

但无论如何,您都可以使用一些解决方法来实现它。您需要自己解析收到的表单数据。另一个问题是 PHP 不会让你看到原始的 mutlipart/form-data,所以你需要:

。另一种方法是修补 PHP 解释器。 :/

You're screwed.

But you can use a couple of workarounds to achieve it anyway. You'll need to parse the received form data yourself. Another problem is that PHP won't let you see the raw mutlipart/form-data, so you need:

The alternative is to patch the PHP interpreter. :/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文