CDNxL's avatar
Level 1

Storage::put vs Storage::putFile*

What is the practical difference between these methods?

Docs said that put() store raw file contents on a disk (like file_put_contents?), and putFile() - putFileAs() will manage automatically the streams.

Using streams is greatly recommended when dealing with large files.

I don't know what "Automatic Streaming" means.

Thanks.

0 likes
1 reply
wilburpowery's avatar

Let's take a look at the source code.

public function put($path, $contents, $lock = false)
{
     return file_put_contents($path, $contents, $lock ? LOCK_EX : 0);
}
/**
 * Store the uploaded file on the disk.
 *
 * @param  string  $path
 * @param  \Illuminate\Http\File|\Illuminate\Http\UploadedFile  $file
 * @param  array  $options
 * @return string|false
 */
public function putFile($path, $file, $options = [])
 {
     return $this->putFileAs($path, $file, $file->hashName(), $options);
 }

put does indeed only use file_put_contents. putFile on the other hand is used to save on the disk a file that has been uploaded (Http Request).

2 likes

Please or to participate in this conversation.