Category: File Handling

  • Listing Files

    Windows command DIR and Linux command ls both display the list of files in the current directory. These commands can be operated with different switches to apply conditions on the list of files displayed. PHP provides a couple of options for programmatically listing files in a given directory. Why List Files? Listing files is useful…

  • Create Directory

    Computer files are stored in the local storage device (called drive) in a hierarchical order, where a directory contains one or more files as well as sub-directories. Respective DOS commands defined in operating systems Windows, Linux etc. are used to create and manage directories. PHP provides directory management functions to create a directory, change the current…

  • File Permissions

    The concept of permissions is at the core of Unix/Linux file system. The permissions determine who can access a file and how one can access a file. File permissions in Linux are manipulated by the chmod command, which can be run inside the Linux terminal. PHP provides the chmod() function with which you can handle file permissions programmatically.…

  • Handle CSV File

    Popular spreadsheet programs use the CSV file format (which stands for Comma Separated Values) to export worksheet data in plain text. Each line in the file represents one row of the worksheet, with values in each column separated by commas. For example, a CSV file with names and ages might look like this − Name,Age…

  • Delete File

    In this chapter, we will learn how to remove a file using PHP. When maintaining data on a server, deleting files is an important step and PHP has simple methods to help with this. The unlink() Function PHP doesn’t have either a delete keyword or a delete() function. Instead, it provides the unlink() function, which when called, deletes a file from…

  • Append File

    Appending data to a file is a common PHP action. This chapter will show you how to do it step by step in simple ways. We will talk about what it means to append to a file, why you might want to do so, and how to do it with PHP code examples. What is…

  • Copy File

    When creating websites or applications in PHP, you may need to manage files. It involves generating, editing, moving and copying files. Copying files is an important step because it allows you to generate backups or duplicate resources without damaging the original file. With this chapter, we will see how to copy files with PHP. Different…

  • Download File

    In this chapter we will learn how to download files using PHP. This chapter is created for beginners, so we will explain everything step by step. By the end, you will know how to make it easy for users to download files from your website! Why Download Files in PHP? Websites commonly allow visitors to…

  • File Existence

    When working with files in PHP, one important task is to detect whether a specific file exists. This helps make sure that your program does not face errors while trying to access files that may not exist. This chapter will show you how to use basic examples to validate the presence of a file. It…

  • Write File

    This chapter will show you how to create and write files in PHP. PHP is a popular programming language for creating dynamic web pages and applications. Writing files helps you to store data, log messages and create content on the server. What is File Writing? In PHP, file writing means either creating a new file…