Skip to content

Tag: file

Quickest Way to Read First Line from File

What’s the quickest, easiest way to read the first line only from a file? I know you can use file, but in my case there’s no point in wasting the time loading the whole file. Preferably a one-liner.

PHP: how can I get file creation date?

I am reading a folder with lots of files. How can I get the creation date of a file. I don’t see any direct function to get it. There are filemtime and filectime. And if the file hasn’t been modified, what will happen? Answer Use filectime. For Windows it will return the creation time, and for Uni…

is_file or file_exists in PHP

I need to check if a file is on HDD at a specified location ($path.$file_name). Which is the difference between is_file() and file_exists() functions and which is better/faster to use in PHP? Answer is_file() will return false if the given path points to a directory. file_exists() will return true if the give…

How can I change a file’s extension using PHP?

How can I change a file’s extension using PHP? Ex: photo.jpg to photo.exe Answer In modern operating systems, filenames very well might contain periods long before the file extension, for instance: PHP provides a way to find the filename without the extension that takes this into account, then just add …