GithubHelp home page GithubHelp logo

folded-php / file Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 39 KB

Manipulate files with functions for your web app.

Home Page: https://packagist.org/packages/folded/file

License: MIT License

PHP 97.40% Dockerfile 2.60%
file php csv

file's Introduction

folded/history

Manipulate files with functions for your web app.

Build Status Maintainability TODOs

Summary

About

I created this library, to avoid having to throw exception in my code when I use the file functions.

Folded is a constellation of packages to help you setting up a web app easily, using ready to plug in packages.

Features

  • Will throw an Exception if an error occured while using the functions
  • Have the exact same signature as the native functions

Requirements

  • PHP version >= 7.4.0
  • Composer installed

Installation

In your root folder, run this command:

composer required folded/file

Examples

1. Open a file

In this example, we will get an opened file.

use function Folded\openFile;

$file = openFile("path/to/file.txt", "r");

2. Close a file

In this example, we will close an opened file.

use function Folded\openFile;
use function Folded\closeFile;

$file = openFile("path/to/file.txt", "r");

closeFile($file);

3. Delete a file

In this example, we will delete an existing file.

use function Folded\deleteFile;

deleteFile("path/to/file.txt");

4. Write a CSV row to a file

In this example, we will write a CSV row in a file.

use function Folded\openFile;
use function Folded\addCsvRowToFile;

$file = openFile("path/to/file.csv", "w");

addCsvRowToFile($file, ["foo", "bar"]);

5. Read a CSV row from a file

In this example, we will get a CSV row from a file. Subsequent calls will get the next rows from the file.

use function Folded\openFile;
use function Folded\getCsvRowFromFile;

$file = openFile("path/to/file.csv", "r");

$firstRow = getCsvRowFromFile($file);
$secondRow = getCsvRowFromFile($file);

6. Rename a file

In this example, we will rename a file.

use function Folded\changeName;

changeName("path/to/old.txt", "path/to/new.txt");

7. Write on file

In this example, we will write on an opened file.

use function Folded\writeOnFile;

$file = fopen("path/to/file.txt");

writeToFile($file, "some text");

If you need to get the number of bytes written, get the return of the function.

use function Folded\writeOnFile;

$file = fopen("path/to/file.txt");

$numberOfBytesWritten = writeToFile($file, "some text");

echo "$numberOfBytesWritten bytes written";

Version support

7.3 7.4 8.0
v0.1.0 ✔️
v0.2.0 ✔️

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.