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)
));

Tuesday, April 12, 2016

input array sum with jQuery

Example how sum all values of those fields

<input type="hidden" name="hidden[1]" class="sum" value="31">
<input type="hidden" name="hidden[2]" class="sum" value="21">
<input type="hidden" name="hidden[3]" class="sum" value="321">
<input type="hidden" name="hidden[4]" class="sum" value="-31">
<input type="hidden" name="hidden[5]" class="sum" value="31.12">
<input type="hidden" name="hidden[6]" class="sum" value="0">


If you have 'sum' as a class to define all the elements that must be calculated,
below code should work...


 <script>
 var total = 0;
 $('.sum').each(function () {
      total += parseFloat(this.value);
  });
</script>