Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ralphmrivera's avatar

Wondering why uploading works in php 7.3, but not in php 7.4 with Laravel 6

Currently using laravel/framework v6.9.0

I just updated my local dev environment from PHP 7.3.9 to PHP 7.4.0.

I have a snippet of code that grabs an avatar from Gravatar and then uploads that image to an S3 bucket.

The code looks like this (with an Unsplash image swapped for a Gravatar URL) .

use Illuminate\Support\Facades\Storage;

// Where to store this in the S3 bucket
$destination = 'users/file.jpg';

// The source file to grab
$source = 'https://images.unsplash.com/photo-1500648767791-00dcc994a43e?fit=crop&crop=faces&w=500&h=500';

// Optional stuff for AWS S3
$options = ['visibility' => 'private', 'Tagging' => 'collection=users&type=avatars'];

// Upload file
Storage::disk('s3')->put($destination, fopen($source, 'r'), $options);

In PHP 7.3.9 this workes perfectly, but in PHP 7.4.0, I get the following error:

PHP Notice: Trying to access array offset on value of type bool in /home/vagrant/project/vendor/league/flysystem/src/Util.php on line 276

I dug around in the flysystem files, but I'm not sure why this is not working. Can anyone help explain why this is happening and how I get this functionality working in 7.4.

0 likes
6 replies
shez1983's avatar

can you post the whole string of messages. also if you have whoops you can look at 'params' being passed from file to file and see which valuesare now booleans but were arrays before

1 like
ralphmrivera's avatar

I'm running this in Tinker and TinkerWell so I don't have that output.

ralphmrivera's avatar

I got this working by substituting Guzzle for fopen(). Not sure if this is ideal, though.

use Illuminate\Support\Facades\Storage;
use GuzzleHttp\Client;

// Where to store this in the S3 bucket
$destination = 'users/file.jpg';

// The source file to grab
$source = 'https://images.unsplash.com/photo-1500648767791-00dcc994a43e?fit=crop&crop=faces&w=500&h=500';

// Optional stuff for AWS S3
$options = ['visibility' => 'private', 'Tagging' => 'collection=users&type=avatars'];

// Upload file
Storage::disk('s3')->put($destination, ((new Client)->request('GET', $source))->getBody(), $options);
ralphmrivera's avatar

Thanks so much. Do you have any thoughts on which method is better? fopen() vs. Guzzle?

fylzero's avatar
fylzero
Best Answer
Level 67

@ralphmrivera Guzzle will be more reliable but add code complexity. I use file_get_contents sometimes in various apps (similar to fopen)... you just need to know that it can break in certain environments... probably best to use Guzzle.

2 likes

Please or to participate in this conversation.