2016-08-12 126 views
2

錯誤,當我使用CI上傳S3文件,我得到了錯誤信息Message: S3::inputFile(): Unable to open input file:filename.jpgS3上傳笨

這裏是我的代碼

$time = Time(); 
if(!empty($_FILES['productImage']['name'])){ 
$file_name  = $_FILES['productImage']['name']; 
$productImageName = 'PRD_'.$time.$_FILES['productImage']['name']; 
if ($this->s3->putObjectFile($file_name, "bucketname", $productImageName, S3::ACL_PUBLIC_READ)) { 
    echo "We successfully uploaded your file.";exit; 
}else{ 
    echo "Something went wrong while uploading your file... sorry.";exit; 
} 
} 

回答

0

海我使用CI在S3上傳文件中的另一個解決方案。在這裏,我共享代碼。它將從GitHub的人在未來

代碼有所幫助:https://github.com/fcosrno/aws-sdk-php-codeigniter

而且我的代碼:

$this->load->library('aws_sdk'); 
try{ 
    $aws_object=$this->aws_sdk->saveObject(array(
    'Bucket'  => 'mybucket', 
    'Key'   => 'QA/product/'.$newImagename, 
    'ACL'   => 'public-read', 
    'SourceFile' => $_FILES['productImage']['tmp_name'], 
    'ContentType' => 'image/jpeg' 
))->toArray(); 

}catch (Exception $e){ 
    $error = "Something went wrong saving your file.\n".$e; 
    echo $error; 
}