How can I upload a file to amazon S3 with Codeigniter/PHP?
amazon-s3, codeigniter, file-upload, php
Solution
I switched to a different S3 PHP library, which is also referred to as S3.php, that is part of this really nice Netuts tutorial source code.
Just plugging in my AWS keys and bucket name into the demo's page.php file, I was able to upload to my bucket in like 2 minutes. So this tutorial is super easy. Very exciting!
Problem
I'm trying to upload a file to my Amazon S3 bucket. My friend had this working on our site in the past but a year later its busted and I can't figure out what's wrong. We are using the S3 PHP library developed by Geoff gaudreault. This library looks pretty straightforward to me, really it looks like there is one key function: `putObject()`. Unfortunately, I'm not even getting out of the gate. I'm getting the following error message: `Error 324 (net::ERR_EMPTY_RESPONSE): The server closed the connection without sending any data.` Here's my codeigniter PHP for my upload form `action`: ``` function s3(){ $config['upload_path'] = $_SERVER["DOCUMENT_ROOT"].'/temp/'; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = '1000000'; $config['max_width'] = '1024000'; $config['max_height'] = '768000'; $this->load->library('upload', $config); if ( ! $this->upload->do_upload()) { $error = array('error' => $this->upload->display_errors()); print_r($error); echo 'failure'; } else { $data = array('upload_data' => $this->upload->data()); $fn = $data['file_name']; $type = substr($fn, strrpos($fn, '.') + 1); $this->load->library('s3'); $temp_file_path = $_SERVER["DOCUMENT_ROOT"]."/temp/" . $data['file_name']; $contents = read_file($temp_file_path); // will this blow up or timeout for large files?! $newFileName = uniqid().".".substr($temp_file_path, strrpos($temp_file_path, '.') + 1); $contentPath = "mysite.com/Images"; $this->s3->putObject($newFileName, $contents, $contentPath, 'private', $type); echo 'success'; } } ``` Does anyone have any thoughts?