Search code examples
phpapacheamazon-s3file-uploadlocalhost

AWS s3 Uploading files on localhost, but not working in the real URL


function setUploadAWS($ORIGEM, $DESTINO, $DIR) {

    $BUCKET = 'some-bucket';

    $ACCESS_KEY = "some-access-key";
    $SECRET_KEY = "some-secret-key";
    $credentials = new Aws\Credentials\Credentials($ACCESS_KEY, $SECRET_KEY);

    try {

        $s3 = new S3Client([
            'version'     => 'latest',
            'region'      => 'us-east-1',
            'credentials' => $credentials
        ]);

        $result = $s3->putObject([
            'Bucket'     => $BUCKET,
            'Key'        => $DIR . $DESTINO,
            'SourceFile' => $ORIGEM,
        ]);
    } catch (S3Exception $e) {
        echo $e->getMessage() . "\n";
    }

The aws code for uploading pictures is working to upload files through localhost, but it's not able to upload files to the system.


Solution

  • The solution was to change parameters allow_url_fopen and allow_url_include to On:

    allow_url_fopen= On
    allow_url_include= On
    

    The parameters are listed on php.ini.

    Path = apache2/php.ini