Friday, June 10, 2016

Check if array value is empty in an existing array

Here is my array ouput

 Array
(
    [1] => 1
    [2] => 2
    [3] => 
)

How do I know the [3] => is empty?

Solution:

$array = array('one', 'two', '');

if(count(array_filter($array)) == count($array)) {
    echo 'OK';
} else {
    echo 'ERROR';
}

 

Tuesday, April 26, 2016

PutObject into directory Amazon s3 / PHP

In Laravel.5 ,  You should be able to use the temp file contents in the API,
and specify the file name separately. 


// Get the UploadedFile object
$file = Request::file('uploadImageFile');

// You can store this but should validate it to avoid conflicts
$original_name = $file->getClientOriginalName();

// This would be used for the payload
$file_path = $file->getPathName();

// Example S3 API upload
$s3client->putObject([
    'Key' => $original_name, // This will overwrite any other files with same name
    'SourceFile' => $file_path,
    'Bucket' => 'bucket_name'
]);


// Example

$localImage = '/Users/jim/Photos/summer-vacation/DP00342654.jpg';
$s3->putObject(array(
    'Bucket'     => 'my-uniquely-named-bucket',
    'SourceFile' => $localImage,
    'Key'        => 'photos/summer/' . basename($localImage)
));