upload big file to the cloud with php
I'm trying to upload big files to rackspace cloud using Compass API: http://www.compasswebpublisher.com/php/rackspace-cloudfiles-php-api
It's working fine for small files (jpg) but when the file is more then 100MB the script crash. Well, to be exact, the script just stops.
$cf = new Compass_Service_Rackspace_Cloudfiles('myid', 'myApiKey', Compass_Service_Rackspace_Cloudfiles::UK_AUTHURL);
$cf->auth();
set_time_limit(60*60);
ini_set("memory_limit","256M");开发者_StackOverflow中文版
ini_set('upload_max_filesize', '700M');
ini_set('post_max_size', '700M');
$contents = file_get_contents($path);
$cf->putObject('container/filename', $contents);
In a first time I though it was a memory issue, but even with 256M the script is not working.
Any idea why it's not working?
Thanks a lot!
Regards, Pv
I'm not sure what script you're trying to use, but it's probably crashing due to the script timing out unless it's being taken care of.
I wouldn't advise you to use a form to upload a 100 MB file on a regular basis unless it's absolutely necessary and the script is written well to handle limits. That's what FTP is for.
As first solution, I would recommend you to pass 0 set_time_limit
function, because it will make script to be able to run till the end without timeout.
As second solution, I would recommend you to use plupload library for frontend, which will allow you to upload file by chunks. See more about it here http://www.plupload.com/
You can use raskcpace cloud API in order to send files to rackspace cloudfiles.
The workflow to uplaod files would be
- Upload files to your server first.
- Send the file to rackspace cloud file container from the webserver
- Delete the file from your webserver or keep it to your choice.
You can use PHP's input:// stream and XMLHttpRequest to uplaod files in chunks to your webserver. More info here http://www.webiny.com/blog/2012/05/07/webiny-file-upload-with-html5-and-ajax-using-php-streams/
You can find rackspace API at https://github.com/rackspace/php-opencloud
精彩评论