Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected T_CONST #3023

Open
1 task
ryandavern opened this issue Nov 8, 2024 · 1 comment
Open
1 task

Unexpected T_CONST #3023

ryandavern opened this issue Nov 8, 2024 · 1 comment
Assignees
Labels
guidance Question that needs advice or information. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@ryandavern
Copy link

Describe the bug


Parse error: syntax error, unexpected 'const' (T_CONST), expecting variable (T_VARIABLE) in /var/www/rhythmUtils/RhythmWebApp/frontend/api/profile/aws/Aws/S3/S3Client.php on line 237

This issue arises when I go to upload an image via the SDK.

Heres my code:
require 'aws/aws-autoloader.php';

use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;

// Replace these variables with your own details
$spaceName = '';
$region = '';
$accessKey = '';
$secretKey = '';
$endpoint = '';

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    if (isset($_FILES['file']) && $_FILES['file']['error'] == UPLOAD_ERR_OK) {
        $uploadDir = 'uploads/';  // Make sure this directory exists and is writable

        // Get the file extension
        $fileExtension = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);

        // Generate a unique random file name
        $newFileName = uniqid('file_', true) . '.' . $fileExtension;

        // Set the full path for the uploaded file
        $uploadFile = $uploadDir . $newFileName;

        if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadFile)) {
            try {
                // Initialize the S3 client with your credentials
                $s3 = new S3Client([
                    'version' => 'latest',
                    'region'  => $region,
                    'endpoint' => $endpoint,
                    'credentials' => [
                        'key'    => $accessKey,
                        'secret' => $secretKey,
                    ],
                ]);

                // Path to the file you want to upload
                $filePath = $uploadFile;
                // Name of the file in the space
                $keyName = 'image/a/' . basename($filePath);

                // Upload the file to the space
                $result = $s3->putObject([
                    'Bucket' => $spaceName,
                    'Key'    => $keyName,
                    'SourceFile' => $filePath,  // Local path on the server
                    'ACL'    => 'public-read', // Optional: Make the file publicly accessible
                ]);

                echo json_encode(basename($filePath));

            } catch (S3Exception $e) {
                echo "There was an error uploading the file.\n";
                echo $e->getMessage() . "\n";
            }

        } else {
            echo 'Error: Unable to move the uploaded file.';
        }
    } else {
        echo 'Error: No file uploaded or there was an upload error.';
    }
} else {
    echo 'Error: Invalid request method.';
}

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

Image should have uploaded correctly, however, that error is produced when i go to upload. I have attached a copy of the code i used to recreate this issue

Current Behavior


Parse error: syntax error, unexpected 'const' (T_CONST), expecting variable (T_VARIABLE) in /var/www/rhythmUtils/RhythmWebApp/frontend/api/profile/aws/Aws/S3/S3Client.php on line 237

Reproduction Steps

I attached the code I used to upload the image

Possible Solution

No response

Additional Information/Context

No response

SDK version used

3.325.4

Environment details (Version of PHP (php -v)? OS name and version, etc.)

PHP 7.0.33-0ubuntu0.16.04.16 (cli) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies with Zend OPcache v7.0.33-0ubuntu0.16.04.16, Copyright (c) 1999-2017, by Zend Technologies

@ryandavern ryandavern added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 8, 2024
@stobrien89
Copy link
Member

Hi @ryandavern,

Sorry to hear about the issues. This is happening because PHP 7.0 doesn't support visibility modifiers on class constants. We deprecated PHP runtimes below 7.2.5 in August of last year; version 3.279.0 and below are fully compatible with PHP 7.0.

@stobrien89 stobrien89 added guidance Question that needs advice or information. and removed bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 8, 2024
@stobrien89 stobrien89 self-assigned this Nov 8, 2024
@yenfryherrerafeliz yenfryherrerafeliz added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
guidance Question that needs advice or information. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

3 participants