开发者

Downloading file from URL (with cookies!) and uploading it somewhere else, with PHP

I'm currently working on a web service that will need to download a file from a URL, and upload it somewhere else. To be able to download a file, I have to use cookies, so what I've been thinking of doing is using sockets to read the file and upload it while I'm reading it. Theoretical code sample:

while (!feof($downloadHandle)) {
    fwrite($uploadHandle, fread($downloadHandle, 8192));
}

The problem with this is that often these files will be massive, and would consume an incredible amount of bandwidth if I were to run this piece of code on a regular server. Thus I've been considering using Amazon's Web Services, since bandwidth would be cheaper, infinitely scalable, and I'd only pay for what I use.

The problem is that I don't know how best to make use of Amazon for this particular problem. I've been considering setting up EC2 instances with PHP to run this code, but I'm not sure if this is the most appropriate way, or if ther开发者_如何转开发e are better solutions for this type of problem.

As I wrote this question, I realised that I could use wget to download a file. Uploading a file would require cookies, too, and would have to be done over HTTP as well, which, I believe, wput doesn't support, so I am not aware of any command line tools to do it.

Any ideas?


You should use curl for this. I think this here will help you. How use CURLOPT_WRITEFUNCTION when download a file by CURL

And this: http://www.php.net/manual/de/book.curl.php

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜