我正在使用带有 s3 库的 codeingiter,在单个文件上传时一切正常,但是当我尝试上传多张照片及其缩略图时,它挂在第二个 putObject(第一个文件的第一个缩略图)
代码是这样的:
function photosAddAction()
{
$files = array();
$files_data = $_FILES["uploads"];
if (is_array($files_data["name"]))
{
//This is the problem
for ($i = 0; $i < count($files_data['name']); ++$i)
{
$files[] = array(
'name' => $files_data['name'][$i],
'tmp_name' => $files_data['tmp_name'][$i],
);
}
}
else
{
$files[] = $files_data;
}
foreach ($files as $file)
{
//prepare data
$chars = '0123456789abcdefghijklmnopqrstuvwxyz';
$rand = substr(str_shuffle($chars), 0, 6);
//prepare file info
$file['tempDir'] = sys_get_temp_dir();
$file['targetFile'] = $this->uri->segment(2).'_'.time().'_'.$rand;
$file['extension'] = pathinfo($file['name'], PATHINFO_EXTENSION);
//upload original
$this->load->library('s3');
$this->s3->putObject($this->s3->inputFile($file['tmp_name'], false), 'mybucket', 'images/'.$file['targetFile'].'.'.$file['extension'], S3::ACL_PUBLIC_READ);
//create and upload thumbnails
$this->create_thumbnail(array('width' => 800, 'height' => 800, 'file' => $file));
$this->create_thumbnail(array('width' => 100, 'height' => 100, 'file' => $file));
}
function create_thumbnail($data)
{
log_message('info', 'create thumb called');
$new_image ='t'.$data['width'].'x'.$data['height'].'_'.$data['file']['targetFile'].'.'.$data['file']['extension'];
//resize config
$config['image_library'] = 'gd2';
$config['source_image']= $data['file']['tmp_name'];
$config['create_thumb'] = FALSE;
$config['maintain_ratio'] = TRUE;
$config['width'] = $data['width'];
$config['height'] = $data['height'];
//resize image
$this->load->library('image_lib');
log_message('info', 'image_lib');
$this->image_lib->initialize($config);
$this->image_lib->resize();
$this->load->library('s3');
//upload image
log_message('info', 'put');
$putCommand = $this->s3->putObject($this->s3->inputFile($config['source_image'], false), 'mybucket', 'images/'.$new_image, S3::ACL_PUBLIC_READ);
if($putCommand)
{
log_message('info', $data['width'].'x'.$data['height'].' uploaded');
log_message('info', $putCommand->getRequest()->getUrl());
}
else
{
log_message('error', $data['width'].'x'.$data['height'].' upload FAILED');
}
log_message('info', 'put done');
$this->image_lib->clear();
}
最后的日志条目是:
DEBUG - 2013-06-12 20:10:33 --> Model Class Initialized
DEBUG - 2013-06-12 20:10:33 --> Controller Class Initialized
DEBUG - 2013-06-12 20:10:33 --> Image Lib Class Initialized
INFO - 2013-06-12 20:10:40 --> create thumb called
INFO - 2013-06-12 20:10:40 --> image_lib
INFO - 2013-06-12 20:10:41 --> put
谁能指引我正确的方向?
谢谢