Skip to content
Advertisement

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 Unix the change time

.htaccess deny access to specific files? more than one

I am able to disable access to a file with .htaccess, but I don’t know how to disallow multiple files to be viewed (directly, not from includes) They are .php so I can’t disable a file type (like the only tutorials online say..) Or something.. For example “home.php, file.php , test.php” how do I disallow access to all three files

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 given path points to a valid file or directory.

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 the new extension:

Advertisement