Writing to files is as easy as reading from them. In this tutorial, we’ll use the file_put_contents() and fwrite() functions to write and append to files. You’ll also learn how to lock files to avoid trouble when one process writes while the other one reads.
In this tutorial, you will learn how to parse large files, keeping the system’s memory safe. We will use the PHP functions (fgets, fgetc, and fread) that can read chunks of the file content at a time.
fopen() is the function to open a file on disk as a resource. This function gives you access to any file and its contents. When you open a file, you can open it for several purposes, for example, reading, writing, and appending (adding information to the end of the file).
To read data from a file, PHP offers several possibilities. Probably the easiest way is to read it all at once with file_get_contents() function and then output it to the user or read it line by line with file() function.
Learn how to force download files in PHP and how to generate a TXT, CSV, or JSON file on the fly from a string and send it to the browser.
In this tutorial, we’ll create an AJAX form that can upload and validate multiple files.
Learn how to handle multiple file uploads in PHP. You’ll also learn how to select directories (instead of files) with the directory picker attribute and upload the directories content to the server. You’ll also use the new feature “full_path” (as of PHP 8.1), a subkey of $_FILES array to create the exact directory structure of uploaded directories.
In this tutorial, you’ll create functions to automatically rename the uploaded file name, generate a unique file name based on the Unix timestamp, and remove special characters to sanitize the file name.
Learn how to check the file extension and MIME type of the uploaded (or any) file in PHP.