create account

PHP Tutorial #25 File System Part 1 " Fopen, Fread, Fwrite and File_get_contents " by alexendre-maxim

View this thread on: hive.blogpeakd.comecency.com
· @alexendre-maxim ·
$24.28
PHP Tutorial #25 File System Part 1 " Fopen, Fread, Fwrite and File_get_contents "
<html>
<p><img src="https://cdn.steemitimages.com/DQmR2CdPgUAaypJwbE8QhahqDxrabLTM5fHq8ZjTPcVr2fg/bbva-open4u-herramientas-basicas-desarrolladores-php_1.jpg" width="2122" height="1415"/></p>
<p><a href="https://cdn.steemitimages.com/DQmR2CdPgUAaypJwbE8QhahqDxrabLTM5fHq8ZjTPcVr2fg/bbva-open4u-herramientas-basicas-desarrolladores-php_1.jpg">Image Source</a></p>
<h2>Repository</h2>
<p><a href="https://github.com/php/php-src">https://github.com/php/php-src</a> &nbsp;</p>
<h2>What Will I Learn?</h2>
<ul>
  <li>You will learn how to handle the file using the Fopen method.</li>
  <li>You will learn how to open the file with the Opening Mode for reading using the Fread.</li>
  <li>You will learn how to write in a file using the Fwrite method.</li>
  <li>You will learn how to get the content of a file using the file_get_contents method.</li>
</ul>
<h2>Requirements</h2>
<h5>System Requirements:</h5>
<ul>
  <li>Server support PHP , <a href="https://www.apachefriends.org/fr/download.html">Xampp</a> or <a href="http://www.wampserver.com/">Wamp</a> for example</li>
  <li>An IDE like <a href="https://www.sublimetext.com/download">Sublime text</a>.</li>
  <li>Browser (<a href="https://www.google.com/intl/fr_ALL/chrome/">Chrome</a> for example)&nbsp;&nbsp;</li>
</ul>
<h5>OS Support for PHP</h5>
<ul>
  <li>Windows</li>
  <li>macOS</li>
  <li>Linux</li>
</ul>
<h4>Required Knowledge</h4>
<ul>
  <li>HTML language</li>
  <li>CSS language</li>
</ul>
<h2>Difficulty</h2>
<ul>
  <li>&nbsp;Intermediate&nbsp;</li>
</ul>
<h2>Description</h2>
<p>In this tutorial we will learn stuff in the file systems that PHP offers, if you are in the local you work on a management application for example in your pc, and you want to use a system for storing your data for that. We're going to think about databases, but with file management systems, PHP gives us another technique to quickly store our data without access to a DBMS, we can add, modify and delete them through very simple and very efficient methods.</p>
<p>Today we will take 4 methods that are more used to manipulate the files either .txt or another extension, we will learn the "Fopen, Fread, Fwrite and finally file_get_contents" with the necessary parameters.</p>
<h3>Fopen Method</h3>
<p>PHP to process a file and to say that this file can be processed is to use Fopen, Fopen will open the file for both known read and write operations.</p>
<p>It has 2 parameters:</p>
<p>The first parameter can be the name of the file itself or a path to the file itself.</p>
<p>The second is the opening mode :</p>
<p>The opening mode specifically defines file access, the operating system needs to know what you want to do with the file once it is open. It is from there that he can specify the accesses in writing, reading, etc.</p>
<p><img src="https://cdn.steemitimages.com/DQmUsKdMvgjSsnMCNkikkoDUdd1ehBxw2ipCCqxFBsPU45M/Modes.jpg" width="945" height="589"/></p>
<h3>Fread Method</h3>
<p>The fread() method reads up to the value of parameter ' length ' in the file referenced by the first ' handle ' parameter, we can use the variable that we have used to open the file. It stops when one of the following conditions appears :</p>
<p>The value of parameter ' length ' have been read or we can say the size of the file.</p>
<p>The end of the file is reached.</p>
<p>A packet becomes available or the socket timeout time is passed.</p>
<p>It can be used effectively if we can read the complete file, but sometimes we need to read the file line by line for example or character by character and for that we will not use the fread but we will use other functions like<code> fgets()</code>...</p>
<h3>Fwrite Method</h3>
<p>To write in a file you must use one of the functions of php, and for that we will use the function fwrite that's a very important function and easy to handle, this function makes it possible to write the contents in the file passed as paremetre.</p>
<p>It has 3 parameters :&nbsp;</p>
<p>The first parameter is the handle is a resource file system pointer that is usually created using the <code>fopen() </code>function.</p>
<p>The second parameter is the string, which is the content to write in the file.</p>
<p>The third parameter is the length, if the length is supplied the writing will stop after length bytes, or at the end of the string.</p>
<p>It will return the number of bytes written or FALSE if an error occurs.</p>
<p><img src="https://cdn.steemitimages.com/DQmdqVbJDxKcsDwaPBn8BEsQbEu6wejTWh3Bc2xgJ3n5FrQ/capture-20190322-234813.png" width="1010" height="494"/></p>
<h3>File_Get_Contents Method</h3>
<p>To read a file or to obtain the contents of a file we will use the function <code>file_get_contents()</code>, this function will return the data read in a string of character or FALSE if an error occurs.</p>
<p>This function can return FALSE, but it can also return a value equivalent to FALSE</p>
<p>It has 5 parameters :&nbsp;</p>
<p>The first parameter is the file name.</p>
<p>The second is the include_path.</p>
<p>The third is the context.</p>
<p>The fourth parameter is the offset.</p>
<p>The fifth parameter is the maxlen.</p>
<p>The function will return an error if the file name is incorrect or maxlen is less than 0.</p>
<p><img src="https://cdn.steemitimages.com/DQmZi6k5x62L34M7eVGcUgAberCBDRpfP88Cvjj3Br4ahzr/capture-20190323-000257.png" width="1334" height="554"/></p>
<h2>Video Tutorial</h2>
<p>https://www.youtube.com/watch?v=ncKsYF2O9gw&amp;t=11s</p>
<h2>Curriculum</h2>
<ul>
  <li><a href="https://steemit.com/utopian-io/@alexendre-maxim/php-tutorial-11-string-methods-addslaches-chr-chop-and-chunksplite">PHP Tutorial #11 String Methods ( Addslaches, Chr, Chop and Chunk_splite )</a></li>
  <li><a href="https://steemit.com/utopian-io/@alexendre-maxim/php-tutorial-12-string-methods-bin2hex-countchars-explode-and-hex2bin">PHP Tutorial #12 String Methods ( Bin2Hex, Count_Chars, Explode and Hex2Bin )</a></li>
  <li><a href="https://steemit.com/utopian-io/@alexendre-maxim/php-tutorial-13-string-methods-implode-join-lcfirst-ltrim-and-fprintf">PHP Tutorial #13 String Methods (Implode, Join, Lcfirst, Ltrim and Fprintf )</a></li>
  <li><a href="https://steemit.com/utopian-io/@alexendre-maxim/php-tutorial-14-string-methods-md5file-md5-nl2br-and-addcslaches">PHP Tutorial #14 String Methods (Md5_File, Md5, Nl2br and Addcslaches )</a></li>
  <li><a href="https://steemit.com/utopian-io/@alexendre-maxim/php-tutorial-15-string-methods-numberformat-ord-parsestr-print-and-printf">PHP Tutorial #15 String Methods (Number_Format, Ord, Parse_Str, Print and Printf )</a></li>
  <li><a href="https://steemit.com/utopian-io/@alexendre-maxim/php-tutorial-16-string-methods-quotemeta-rtrim-sha1file-and-sha1">PHP Tutorial #16 String Methods (QuoteMeta, Rtrim , Sha1_file and Sha1 )</a></li>
  <li><a href="https://steemit.com/utopian-io/@alexendre-maxim/php-tutorial-17-mathematical-methods-abs-acos-acosh-and-asin">PHP Tutorial #17 Mathematical Methods (Abs, Acos , Acosh and Asin )</a></li>
  <li><a href="https://steemit.com/utopian-io/@alexendre-maxim/php-tutorial-18-get-and-post-methods-and-usdserver-variables">PHP Tutorial #18 ( GET and POST ) Methods and $_SERVER Variables</a></li>
  <li><a href="https://steemit.com/utopian-io/@alexendre-maxim/php-tutorial-19-include-and-require-globals-variable-request-and-usdserver-variables">PHP Tutorial #19 ( Include and Require ) , Globals Variable, Request and $_SERVER Variables</a></li>
  <li><a href="https://steemit.com/utopian-io/@alexendre-maxim/php-tutorial-20-the-cookie-how-to-create-modify-and-delete-a-cookie">PHP Tutorial #20 The Cookie How To Create , Modify And Delete A Cookie</a></li>
  <li><a href="https://steemit.com/utopian-io/@alexendre-maxim/php-tutorial-21-the-session-how-to-create-modify-and-delete-a-session">PHP Tutorial #21 The Session How To Create , Modify And Delete A Session</a></li>
  <li><a href="https://steemit.com/utopian-io/@alexendre-maxim/php-tutorial-22-the-outputbuffer-and-how-to-control-it">PHP Tutorial #22 The Output_Buffer And How To Control It</a></li>
  <li><a href="https://steemit.com/utopian-io/@alexendre-maxim/php-tutorial-23-filters-part-1-filtervalidate">PHP Tutorial #23 Filters Part 1 " FILTER_VALIDATE "</a></li>
  <li>&nbsp;<a href="https://steemit.com/utopian-io/@alexendre-maxim/php-tutorial-24-filters-part-2-filtersanitize">PHP Tutorial #24 Filters Part 2 " FILTER_SANITIZE "</a></li>
</ul>
<h2>Proof of Work Done</h2>
<p>https://github.com/alexendre-maxim/PHP-Tutorial/blob/master/R4.php</p>
<p>https://github.com/alexendre-maxim/PHP-Tutorial/blob/master/R4I.php</p>
<p>https://github.com/alexendre-maxim/PHP-Tutorial/blob/master/R4T.php</p>
</html>
πŸ‘  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 56 others
properties (23)
authoralexendre-maxim
permlinkphp-tutorial-25-file-system-part-1-fopen-fread-fwrite-and-filegetcontents
categoryutopian-io
json_metadata{"tags":["utopian-io","video-tutorials","video","programming"],"image":["https://cdn.steemitimages.com/DQmR2CdPgUAaypJwbE8QhahqDxrabLTM5fHq8ZjTPcVr2fg/bbva-open4u-herramientas-basicas-desarrolladores-php_1.jpg","https://cdn.steemitimages.com/DQmUsKdMvgjSsnMCNkikkoDUdd1ehBxw2ipCCqxFBsPU45M/Modes.jpg","https://cdn.steemitimages.com/DQmdqVbJDxKcsDwaPBn8BEsQbEu6wejTWh3Bc2xgJ3n5FrQ/capture-20190322-234813.png","https://cdn.steemitimages.com/DQmZi6k5x62L34M7eVGcUgAberCBDRpfP88Cvjj3Br4ahzr/capture-20190323-000257.png","https://img.youtube.com/vi/ncKsYF2O9gw/0.jpg"],"links":["https://cdn.steemitimages.com/DQmR2CdPgUAaypJwbE8QhahqDxrabLTM5fHq8ZjTPcVr2fg/bbva-open4u-herramientas-basicas-desarrolladores-php_1.jpg","https://github.com/php/php-src","https://www.apachefriends.org/fr/download.html","http://www.wampserver.com/","https://www.sublimetext.com/download","https://www.google.com/intl/fr_ALL/chrome/","https://www.youtube.com/watch?v=ncKsYF2O9gw&t=11s","https://steemit.com/utopian-io/@alexendre-maxim/php-tutorial-11-string-methods-addslaches-chr-chop-and-chunksplite","https://steemit.com/utopian-io/@alexendre-maxim/php-tutorial-12-string-methods-bin2hex-countchars-explode-and-hex2bin","https://steemit.com/utopian-io/@alexendre-maxim/php-tutorial-13-string-methods-implode-join-lcfirst-ltrim-and-fprintf","https://steemit.com/utopian-io/@alexendre-maxim/php-tutorial-14-string-methods-md5file-md5-nl2br-and-addcslaches","https://steemit.com/utopian-io/@alexendre-maxim/php-tutorial-15-string-methods-numberformat-ord-parsestr-print-and-printf","https://steemit.com/utopian-io/@alexendre-maxim/php-tutorial-16-string-methods-quotemeta-rtrim-sha1file-and-sha1","https://steemit.com/utopian-io/@alexendre-maxim/php-tutorial-17-mathematical-methods-abs-acos-acosh-and-asin","https://steemit.com/utopian-io/@alexendre-maxim/php-tutorial-18-get-and-post-methods-and-usdserver-variables","https://steemit.com/utopian-io/@alexendre-maxim/php-tutorial-19-include-and-require-globals-variable-request-and-usdserver-variables","https://steemit.com/utopian-io/@alexendre-maxim/php-tutorial-20-the-cookie-how-to-create-modify-and-delete-a-cookie","https://steemit.com/utopian-io/@alexendre-maxim/php-tutorial-21-the-session-how-to-create-modify-and-delete-a-session","https://steemit.com/utopian-io/@alexendre-maxim/php-tutorial-22-the-outputbuffer-and-how-to-control-it","https://steemit.com/utopian-io/@alexendre-maxim/php-tutorial-23-filters-part-1-filtervalidate","https://steemit.com/utopian-io/@alexendre-maxim/php-tutorial-24-filters-part-2-filtersanitize","https://github.com/alexendre-maxim/PHP-Tutorial/blob/master/R4.php","https://github.com/alexendre-maxim/PHP-Tutorial/blob/master/R4I.php","https://github.com/alexendre-maxim/PHP-Tutorial/blob/master/R4T.php"],"app":"steemit/0.1","format":"html"}
created2019-03-22 23:04:21
last_update2019-03-22 23:04:21
depth0
children7
last_payout2019-03-29 23:04:21
cashout_time1969-12-31 23:59:59
total_payout_value18.490 HBD
curator_payout_value5.790 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length8,661
author_reputation18,071,828,077,109
root_title"PHP Tutorial #25 File System Part 1 " Fopen, Fread, Fwrite and File_get_contents ""
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id81,764,297
net_rshares37,827,406,173,089
author_curate_reward""
vote details (120)
@rosatravels ·
$12.99
Hi @alexendre-maxim,


Thank you for another tutorial into the video category.

You have done a good job in this tutorial by teaching 4 diffeent good concepts.

The delivery in your video tutorial is also improving with diction and structure.

Keep up the good work.

Your contribution has been evaluated according to [Utopian policies and guidelines](https://join.utopian.io/guidelines), as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, [click here](https://review.utopian.io/result/9/1-2-2-2-2-2-1-2-3-).

---- 
Need help? Chat with us on [Discord](https://discord.gg/uTyJkNm).

[[utopian-moderator]](https://join.utopian.io/)
πŸ‘  , , , , , , , , , ,
properties (23)
authorrosatravels
permlinkre-alexendre-maxim-php-tutorial-25-file-system-part-1-fopen-fread-fwrite-and-filegetcontents-20190325t065000808z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"users":["alexendre-maxim"],"links":["https://join.utopian.io/guidelines","https://review.utopian.io/result/9/1-2-2-2-2-2-1-2-3-","https://discord.gg/uTyJkNm","https://join.utopian.io/"],"app":"steemit/0.1"}
created2019-03-25 06:50:03
last_update2019-03-25 06:50:03
depth1
children2
last_payout2019-04-01 06:50:03
cashout_time1969-12-31 23:59:59
total_payout_value9.856 HBD
curator_payout_value3.138 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length720
author_reputation422,827,447,688,168
root_title"PHP Tutorial #25 File System Part 1 " Fopen, Fread, Fwrite and File_get_contents ""
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id81,897,324
net_rshares19,969,968,384,424
author_curate_reward""
vote details (11)
@alexendre-maxim ·
Thank you @rosatravels, I am happy with this response .
properties (22)
authoralexendre-maxim
permlinkre-rosatravels-re-alexendre-maxim-php-tutorial-25-file-system-part-1-fopen-fread-fwrite-and-filegetcontents-20190329t192719720z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"users":["rosatravels"],"app":"steemit/0.1"}
created2019-03-29 19:26:54
last_update2019-03-29 19:26:54
depth2
children0
last_payout2019-04-05 19:26:54
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length55
author_reputation18,071,828,077,109
root_title"PHP Tutorial #25 File System Part 1 " Fopen, Fread, Fwrite and File_get_contents ""
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id82,166,075
net_rshares0
@utopian-io ·
Thank you for your review, @rosatravels! Keep up the good work!
properties (22)
authorutopian-io
permlinkre-re-alexendre-maxim-php-tutorial-25-file-system-part-1-fopen-fread-fwrite-and-filegetcontents-20190325t065000808z-20190327t224516z
categoryutopian-io
json_metadata"{"app": "beem/0.20.17"}"
created2019-03-27 22:45:18
last_update2019-03-27 22:45:18
depth2
children0
last_payout2019-04-03 22:45:18
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length63
author_reputation152,955,367,999,756
root_title"PHP Tutorial #25 File System Part 1 " Fopen, Fread, Fwrite and File_get_contents ""
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id82,064,996
net_rshares0
@steem-ua ·
#### Hi @alexendre-maxim!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
**Feel free to join our [@steem-ua Discord server](https://discord.gg/KpBNYGz)**
properties (22)
authorsteem-ua
permlinkre-php-tutorial-25-file-system-part-1-fopen-fread-fwrite-and-filegetcontents-20190325t070112z
categoryutopian-io
json_metadata"{"app": "beem/0.20.19"}"
created2019-03-25 07:01:12
last_update2019-03-25 07:01:12
depth1
children1
last_payout2019-04-01 07:01:12
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length294
author_reputation23,214,230,978,060
root_title"PHP Tutorial #25 File System Part 1 " Fopen, Fread, Fwrite and File_get_contents ""
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id81,897,668
net_rshares0
@alexendre-maxim ·
Thank you @steem-ua
properties (22)
authoralexendre-maxim
permlinkre-steem-ua-re-php-tutorial-25-file-system-part-1-fopen-fread-fwrite-and-filegetcontents-20190325t070112z-20190329t192929682z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"users":["steem-ua"],"app":"steemit/0.1"}
created2019-03-29 19:29:03
last_update2019-03-29 19:29:03
depth2
children0
last_payout2019-04-05 19:29:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length19
author_reputation18,071,828,077,109
root_title"PHP Tutorial #25 File System Part 1 " Fopen, Fread, Fwrite and File_get_contents ""
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id82,166,153
net_rshares0
@utopian-io ·
Hey, @alexendre-maxim!

**Thanks for contributing on Utopian**.
We’re already looking forward to your next contribution!

**Get higher incentives and support Utopian.io!**
 Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via [SteemPlus](https://chrome.google.com/webstore/detail/steemplus/mjbkjgcplmaneajhcbegoffkedeankaj?hl=en) or [Steeditor](https://steeditor.app)).

**Want to chat? Join us on Discord https://discord.gg/h52nFrV.**

<a href='https://steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1'>Vote for Utopian Witness!</a>
properties (22)
authorutopian-io
permlinkre-php-tutorial-25-file-system-part-1-fopen-fread-fwrite-and-filegetcontents-20190326t043431z
categoryutopian-io
json_metadata"{"app": "beem/0.20.17"}"
created2019-03-26 04:34:33
last_update2019-03-26 04:34:33
depth1
children1
last_payout2019-04-02 04:34:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length597
author_reputation152,955,367,999,756
root_title"PHP Tutorial #25 File System Part 1 " Fopen, Fread, Fwrite and File_get_contents ""
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id81,960,926
net_rshares0
@alexendre-maxim ·
Thank you
properties (22)
authoralexendre-maxim
permlinkre-utopian-io-re-php-tutorial-25-file-system-part-1-fopen-fread-fwrite-and-filegetcontents-20190326t043431z-20190329t192934829z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2019-03-29 19:29:09
last_update2019-03-29 19:29:09
depth2
children0
last_payout2019-04-05 19:29:09
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length9
author_reputation18,071,828,077,109
root_title"PHP Tutorial #25 File System Part 1 " Fopen, Fread, Fwrite and File_get_contents ""
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id82,166,155
net_rshares0