How to Code ACCESS 2022 | Browsers | Css | Htacess | Html | Html5 | Javascript | Microsoft Excel | Mysql | Mysql Dumps | Php | Vb.net | VBscript | Windows <=8 | Windows >=10 | WP | WP Plugin | WP Themes | _Misc Software | ABCDEFGHIJKLMNOPQRSTUVWXYZONPRTOFF codeid operationid title keywords application code languageid show_html show_iframe make_public viewed viewed_date language operation <- Look Inside DataConditions:Order: 1|2|3|4|5|6|7|8|50 Language Operation Title Keywords Application Code Languageid Show Html Show Iframe Make Public Viewed Viewed Date Php Files Making An Image Viewer files images viewer Sometimes i have pictures that people want to view but are too numerous or inconvenient to email. I just do a batch conversion on the images (I use Irfan view a free app) and upload them to a new folder I called "stylists". Using this script in an index.php, I dump it with the pictures. It will show them in your browser. [Create image viewer] $imagedirectory="../stylists/"; $dir = opendir($imagedirectory); while ($file = readdir($dir)){ //for ($i=1; $i<=500; $i++){ // $file = readdir($dir); $fullpath=$current_dir.$file; echo "$file"; } closedir($dir); ?> You can tweak it to your folder requirements Php 753 05/05/2026 Php Files Getting A Files Extension file folder extension File Management function browseDirectoryBFS($startDir) { // Initialize the queue with the starting directory $queue = [realpath($startDir)]; while (!empty($queue)) { // Pull the next directory from the front of the queue $currentDir = array_shift($queue); echo "=== Entering Directory: " . $currentDir . " ===n"; // Use scandir to grab all items inside the directory $items = array_diff(scandir($currentDir), ['.', '..']); // Step 1: Separate files and subdirectories at this level $filesAtCurrentLevel = []; $subDirsAtCurrentLevel = []; foreach ($items as $item) { $fullPath = $currentDir . DIRECTORY_SEPARATOR . $item; if (is_dir($fullPath)) { $subDirsAtCurrentLevel[] = $fullPath; } else { $filesAtCurrentLevel[] = $fullPath; } } // Step 2: Read/Process all files in the current folder first foreach ($filesAtCurrentLevel as $file) { echo "".basename($file) . "n"; // To read the content of the files, uncomment the lines below: // $content = file_get_contents($file); // echo "Content: " . substr($content, 0, 100) . "...n"; } // Step 3: Add subdirectories to the back of the queue // This ensures they wait until all items at the current level finish foreach ($subDirsAtCurrentLevel as $dir) { $queue[] = $dir; } echo "n"; } } // Example usage: Pass your target folder here $path = "/var/www/html/images/photo.jpg"; $pathParts = pathinfo($path); $folder = $pathParts['dirname']; // Returns: /var/www/html/images $file = $pathParts['basename']; // Returns: photo.jpg In PHP, there are several methods to retrieve the file extension from a given filename or path. 1. Using pathinfo(): The pathinfo() function is a versatile function that can extract various components of a file path, including the extension. Code 2. Using SplFileInfo::getExtension(): For object-oriented file handling, the SplFileInfo class provides the getExtension() method. Code getExtension(); echo $extension; // Outputs: jpg ?> 3. Using DirectoryIterator::getExtension(): When iterating through a directory, DirectoryIterator objects also offer the getExtension() method for individual files. Code isFile()) { echo $fileinfo->getFilename() . " extension: " . $fileinfo->getExtension() . "n"; } } ?> Note: If a file does not have an extension, these methods will typically return an empty string. If the filename starts with a dot (e.g., .htaccess), the characters following the dot will be considered the extension. Php 2 05/05/2026 Php Files Reading TXT Files fclose fgets fopen fread filesize feof read file whole line character [Reading the Whole File] The fread function reads a number of bytes from a file, up to the end of the file (whichever comes first). The filesize function returns the size of the file in bytes, and can be used with the fread function, as in the following example. $listFile = "junk.txt"; if (!($fp = fopen($listFile, "r"))) exit("Unable to open the input file, $listFile."); $buffer = fread($fp, filesize($listFile)); print "$buffer\n"; fclose($fp); ?> [Reading Line by Line] The fgets function is used to read a line at a time. The function takes two parameters, the file handle, and the number of bytes to read. The function reads data up to a new line, or the number of bytes specified (whichever comes first), and returns the line read. The following is an example of using the fgets function. if (!($fp = fopen("junk.txt", "r"))) exit("Unable to open the input file."); while (!feof($fp)) { $buffer = fgets($fp, 1024); print "$buffer\n"; } fclose($fp); ?> [Reading a Character at a time] The fgetc() function is used to read a single character from a file. Note: After a call to this function the file pointer has moved to the next character. Example The example below reads a file character by character, until the end of file is true: if (!($f=fopen("welcome.txt","r"))) exit("Unable to open file."); while (!feof($f)) { $x=fgetc($f); echo $x; } fclose($f); ?> Php 1291 05/05/2026 Php Files Write To Txt File fopen fwrite rewind fopen write file Writing to Files The fwrite function is used to write a string, or part of a string to a file. The function takes three parameters, the file handle, the string to write, and the number of bytes to write. If the number of bytes is omitted, the whole string is written to the file. If you want the lines to appear on separate lines in the file, use the \n character. Note: Windows requires a carriage return character as well as a new line character, so if you're using Windows, terminate the string with \r\n. The following example logs the visitor to a file, then displays all the entries in the file. $logFile = "stats.txt"; // Open the file in append/read mode $fp = fopen($logFile, "a+"); // Create a string containing the user details $userDetails = $HTTP_USER_AGENT; if (isset($HTTP_REFERER)) $userDetails = $userDetails . " $HTTP_REFERER \r\n"; else $userDetails = $userDetails . "\r\n"; // Write the user details to the file fwrite($fp, "$userDetails"); // Move to the start of the file rewind($fp); $entries = 0; // Display each line in the file while(!feof($fp)) { $buffer = fgets($fp, 1024); if ($buffer != "") { print $buffer; $entries++; } } // Show a summary print "There are $entries entries in the log file"; fclose ($fp); ?>