1
The php codeIgniter application, which runs in windows, when ported to the server gives the following error:
Parse error: syntax error, Unexpected '[' in /home/givix/Domains/givix.com.br/public_html/givix/application/Libraries/Amazon3integration_lib.php on line 79
PHP Error was encountered
Severity: Parsing Error
Message: syntax error, Unexpected '['
Filename: Libraries/Amazon3integration_lib.php
Line Number: 79
Backtrace: (...)
Not locally. So I guess it’s not logical, I thought it was some server configuration.
I made some modifications to the file .htaccess, but I don’t know anyone ever had a similar problem.
Lembando that the local machine is windows and the server is linux. (cent)
Local configuration:
- win 10
- easyphp 16
- Apache 2.4.18 x86
- PHP 5.6.19 x86
- Mysql 5.7.11 x86
Web setup:
- I’ll check on
The page that is set the error is this:
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class amazon3integration_lib
{
public $bucket_name = "teste";
public $region = 'eu-west-1';
public $version = 'latest';
public $scheme = 'http';
public $s3Client = null;
public function __construct(array $config = array(), $reset = TRUE)
{
$reflection = new ReflectionClass($this);
if ($reset === TRUE)
{
$defaults = $reflection->getDefaultProperties();
foreach (array_keys($defaults) as $key)
{
if ($key[0] === '_')
{
continue;
}
if (isset($config[$key]))
{
if ($reflection->hasMethod('set_'.$key))
{
$this->{'set_'.$key}($config[$key]);
}
else
{
$this->$key = $config[$key];
}
}
else
{
$this->$key = $defaults[$key];
}
}
}
else
{
foreach ($config as $key => &$value)
{
if ($key[0] !== '_' && $reflection->hasProperty($key))
{
if ($reflection->hasMethod('set_'.$key))
{
$this->{'set_'.$key}($value);
}
else
{
$this->$key = $value;
}
}
}
}
//AWS account setting
define('AWS_ACCESS_KEY',"AWS-KEY");
define('AWS_SECRET_KEY',"AWS-SECRET");
define('BUCKET_NAME',$this->bucket_name);//The bucket name you want to use for your project
// define('AWS_URL','http://s3-eu-west-1.amazonaws.com/'.$this->bucket_name.'/');
define('AWS_URL','http://'.$this->bucket_name.'.s3.amazonaws.com/');
//check AWS access key is set or not
if(trim(AWS_ACCESS_KEY,"{}")=="AWS_ACCESS_KEY")
{
exit("CI S3 Integration configuration error! Please input the AWS Access Key, "
. "AWS Secret Key and Bucket Name in applicatin/libraries/cis3integration_lib.php file");
}
require_once('amazonSdk/aws-autoloader.php');
//Create S3 client
$sharedConfig = [
'region' => $this->region,
'version' => $this->version,
'scheme' => $this->scheme,
'credentials' => [
'key' => AWS_ACCESS_KEY,
'secret' => AWS_SECRET_KEY,
],
];
$sdk = new Aws\Sdk($sharedConfig);
$this->s3Client = $sdk->createS3();
}
/**
* Delete S3 Object
*
* @access public
*/
function delete_s3_object($file_path)
{
$response = $this->s3Client->deleteObject(array(
'Bucket' => $this->bucket_name,
'Key' => $file_path
));
return true;
}
/**
* Copy S3 Object
*
* @access public
*/
function copy_s3_file($source,$destination)
{
$response = $this->s3Client->copyObject(array(
'Bucket' => $this->bucket_name,
'Key' => $destination,
'CopySource' => "{$this->bucket_name}/{$source}",
));
if($response['ObjectURL'])
{
return true;
}
return false;
}
/**
* Create a new bucket in already specified region
*
* @access public
*/
function create_bucket($bucket_name="",$region="")
{
$promise = $this->s3Client->createBucketAsync(['Bucket' => $bucket_name]);
try {
$result = $promise->wait();
return true;
} catch (Exception $e) {
//echo "exception";exit;
//echo $e->getMessage();
return false;
}
}
}
The stretch that he arrow the error is this:
$sharedConfig = [
'region' => $this->region,
'version' => $this->version,
'scheme' => $this->scheme,
'credentials' => [
'key' => AWS_ACCESS_KEY,
'secret' => AWS_SECRET_KEY,
],
];
From what I see should be php configuration, because by the error saying that in its array opening
[...]
is not recognized on the server, if I am not mistaken, can only be so from version 5.5– Marcelo Diniz
correct friend ... I just checked here also... now I discovered that the version of my server is outdated, I made the modification to old php syntax there passed blz, only that started to give error in the lib ... I returned the original code and am providing the update of the server. for reference my modified code had been like this..
– Rodrigo Givisiez