Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Drupal 8 Module Development

You're reading from   Drupal 8 Module Development Build and customize Drupal 8 modules and extensions efficiently

Arrow left icon
Product type Paperback
Published in Oct 2017
Publisher Packt
ISBN-13 9781782168775
Length 566 pages
Edition 1st Edition
Languages
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
Daniel Sipos Daniel Sipos
Author Profile Icon Daniel Sipos
Daniel Sipos
Arrow right icon
View More author details
Toc

Table of Contents (19) Chapters Close

Preface 1. Developing for Drupal 8 2. Creating Your First Module FREE CHAPTER 3. Logging and Mailing 4. Theming 5. Menus and Menu Links 6. Data Modeling and Storage 7. Your Own Custom Entity and Plugin Types 8. The Database API 9. Custom Fields 10. Access Control 11. Caching 12. JavaScript and the Ajax API 13. Internationalization and Languages 14. Batches, Queues, and Cron 15. Views 16. Working with Files and Images 17. Automated Testing 18. Drupal 8 Security

Stream wrappers

If you've been writing PHP for a long time, you may have needed to work with local or remote files at some point. The following PHP code is a common way to read a file into a variable that you can do something with:

$contents = '';
$handle = fopen("/local/path/to/file/image.jpg", "rb");
while (!feof($handle)) {
 $contents .= fread($handle, 8192);
}
fclose($handle);

This is pretty straightforward. We get a handle to a local file using fopen() and read 8KB chunks of the file using fread() until feof() indicates that we've reached the end of the file. At that point, we use fclose() to close the handle. The contents of the file are now in the variable $contents.

In addition to local files, we can also access remote ones through fopen() in the same exact way but by specifying the actual remote path instead of the local one we...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image