Magento Expert Forum - Improve your Magento experience

Results 1 to 2 of 2

Create, Open, Read, Write, Append, Close, and Delete file in PHP

  1. #1
    Junior Member londondaily's Avatar
    Join Date
    Jun 2013
    Posts
    25
    Thanks
    0
    Thanked 1 Time in 1 Post

    Post Create, Open, Read, Write, Append, Close, and Delete file in PHP

    These tips will help you very much in the first steps working with PHP, at least in file processing.

    Create a File

    $my_file = 'file.txt';
    $handle = fopen($my_file, 'w') or die('Cannot open file: '.$my_file); //implicitly creates file

    Open a File

    $my_file = 'file.txt';
    $handle = fopen($my_file, 'w') or die('Cannot open file: '.$my_file); //open file for writing ('w','r','a')...

    Read a File

    $my_file = 'file.txt';
    $handle = fopen($my_file, 'r');
    $data = fread($handle,filesize($my_file));

    Write to a File

    $my_file = 'file.txt';
    $handle = fopen($my_file, 'w') or die('Cannot open file: '.$my_file);
    $data = 'This is the data';
    fwrite($handle, $data);

    Append to a File

    $my_file = 'file.txt';
    $handle = fopen($my_file, 'a') or die('Cannot open file: '.$my_file);
    $data = 'New data line 1';
    fwrite($handle, $data);
    $new_data = "\n".'New data line 2';
    fwrite($handle, $new_data);

    Close a File

    $my_file = 'file.txt';
    $handle = fopen($my_file, 'w') or die('Cannot open file: '.$my_file);
    //write some data here
    fclose($handle);

    Delete a File

    $my_file = 'file.txt';
    unlink($my_file);

    View more threads in the same category:


  2. #2
    Junior Member
    Join Date
    Sep 2018
    Location
    United Kingdom
    Posts
    228
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default

    Make a File. $my_file = 'file.txt'; $handle = fopen($my_file, 'w') or die('Cannot open record: '.$

    Open a File.

    Peruse a File.

    Keep in touch with a File.

    Add to a File.

    Close a File.

Similar Threads

  1. Easy way to get file extension in PHP
    By speed2x in forum PHP programming
    Replies: 2
    Last Post: 22-04-2019, 09:44 AM
  2. How to redirect Magento to open through www
    By david in forum Programming & Development
    Replies: 0
    Last Post: 19-03-2013, 04:36 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •