开发者

Upload multiple files to remote server with PHP?

I'm about uploading file to remote server using fsockopen() without using context. I'm able to post values but I can't get a way to upload files, like how the header shoul开发者_C百科d be arranged, how Content-Length is calculated.... Can anybody give me an example or an explanation of it?


Can anybody give me an example or an explanation of it?

Hell no! Manually managing HTTP connections is a royal pain in the butt. Smarter people than you and I have worked hard to create libraries for us to use. Use one!

I'm partial to Zend_Http_Client, a mostly stand-alone component in the Zend Framework. It has instructions right there in the documentation on how to perform a file upload.

Some people like PEAR's HTTP_Request2. While it doesn't have an explicit example on how to do uploads in the manual, it can do so via the addUpload method.

If you want something a bit more low-level, you can use the almost-always-there curl extension, which has a variety of file upload options and examples in the manual.

But please, please don't write your own at the socket level. It is entirely unnecessary and will only lead to pain and horrors.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜