Breaking News
Home / Web / PHP (page 3)

PHP

How to list files in a directory in PHP?

<?php if ($handle = opendir(‘/path/to/directory’)) {     echo "Directory handle: $handlen";     echo "Entries:n";     /* This is the correct way to loop over the directory. */     while (false !== ($entry = readdir($handle))) {         echo "$entryn";     }     …

Read More »

How to rename file in PHP?

If you want to rename a file in PHP you can use the rename function. The syntax of the rename function is same as that of the UNIX mv(move) command. The general syntax is: rename(‘/pathA/old_file_name’, ‘/pathB/new_file_name’); e.g. rename(‘/tmp/data.log’, ‘/tmp/data1.log’); [pb_builder]

Read More »

How does fopen function work in PHP?

fopen() Function The fopen() function opens a specified file or URL for reading and/or writing. The syntax of fopen() is fopen(“filename”, “mode”) To open a URL, use http:// or ftp:// at the beginning of the file name string. If the file name begins with anything else, then the file is opened from the filesystem and a file pointer …

Read More »

How to check if file exists in PHP?

Snippet Using the file_exists function it is very easy to check whether a file exists in a given directory or not. Say we want to check if file name audio.mp3 exists or not in /tmp folder. <?php $filename = ‘/tmp/audio.mp3’;   if (file_exists($filename)) { echo "The file $filename exists"; } …

Read More »
Advertisment ad adsense adlogger