Lines Matching full:file

4  * File IO functions
57 * Used to read in a DokuWiki page from file, and send IO_WIKIPAGE_READ events.
61 * The file path should not be changed.
69 * @param string $file filename
76 function io_readWikiPage($file, $id, $rev = false) argument
81 $data = [[$file, true], getNS($id), noNS($id), $rev];
103 * Returns content of $file as cleaned string.
111 * @param string $file filename
113 * @return string|bool the file contents or false on error
117 function io_readFile($file, $clean = true) argument
120 if (file_exists($file)) {
121 if (str_ends_with($file, '.gz')) {
123 $ret = gzfile_get_contents($file);
125 } elseif (str_ends_with($file, '.bz2')) {
127 $ret = bzfile($file);
129 $ret = file_get_contents($file);
141 * Returns the content of a .gz compressed file as string
143 * This reads the file in chunks and decompresses using inflate_* functions
150 * @param string $file filename
155 function gzfile_get_contents($file) argument
157 $fh = @fopen($file, 'rb');
193 * Returns the content of a .bz2 compressed file as string
195 * @param string $file filename
202 function bzfile($file, $array = false) argument
204 $bz = bzopen($file, "r");
238 * Used to write out a DokuWiki page to file, and send IO_WIKIPAGE_WRITE events.
242 * The file path should not be changed.
251 * @param string $file filename
259 function io_writeWikiPage($file, $content, $id, $rev = false) argument
267 $data = [[$file, $content, false], getNS($id), noNS($id), $rev];
283 // for attic files make sure the file has the mtime of the revision
294 * Internal function to save contents to a file.
296 * @param string $file filename path to file
303 function _io_saveFile($file, $content, $append) argument
307 $fileexists = file_exists($file);
309 if (str_ends_with($file, '.gz')) {
311 $fh = @gzopen($file, $mode . '9');
315 } elseif (str_ends_with($file, '.bz2')) {
318 $bzcontent = bzfile($file);
322 $fh = @bzopen($file, 'w');
327 $fh = @fopen($file, $mode);
334 chmod($file, $conf['fperm']);
340 * Saves $content to $file.
348 * @param string $file filename path to file
355 function io_saveFile($file, $content, $append = false) argument
357 io_makeFileDir($file);
358 io_lock($file);
359 if (!_io_saveFile($file, $content, $append)) {
360 msg("Writing $file failed", -1);
361 io_unlock($file);
364 io_unlock($file);
369 * Replace one or more occurrences of a line in a file.
383 * @param string $file filename
394 function io_replaceInFile($file, $oldline, $newline, $regex = false, $maxlines = 0) argument
401 if (!file_exists($file)) return true;
403 io_lock($file);
406 if (str_ends_with($file, '.gz')) {
408 $lines = gzfile($file);
409 } elseif (str_ends_with($file, '.bz2')) {
411 $lines = bzfile($file, true);
413 $lines = file($file);
442 if (!_io_saveFile($file, implode('', $lines), false)) {
443 msg("Removing content from $file failed", -1);
444 io_unlock($file);
448 @unlink($file);
451 io_unlock($file);
456 * Delete lines that match $badline from $file.
460 * @param string $file filename
467 function io_deleteFromFile($file, $badline, $regex = false) argument
469 return io_replaceInFile($file, $badline, '', $regex, 0);
473 * Tries to lock a file
481 * @param string $file filename
485 function io_lock($file) argument
489 $lockDir = $conf['lockdir'] . '/' . md5($file);
508 * Unlocks a file
510 * @param string $file filename
514 function io_unlock($file) argument
518 $lockDir = $conf['lockdir'] . '/' . md5($file);
548 $tmp = dirname($file = call_user_func($types[$ns_type], $ns));
559 io_makeFileDir($file);
569 * Create the directory needed for the given file
571 * @param string $file file name
575 function io_makeFileDir($file) argument
577 $dir = dirname($file);
647 foreach ($files as $file) {
648 if (!@unlink($file)) return false; //abort on any error
683 * downloads a file from the net and saves it
686 * - $file is the full filename to save the file, incl. path
690 * - $file is the directory where the file should be saved
691 * - if successful will return the name used for the saved file, false otherwise
694 * @param string $file path to file or directory where to save
696 * false: uses $file as path to file
698 * @param int $maxSize maximum file size
699 …* @return bool|string if failed false, otherwise true or the name of the file in the give…
704 function io_download($url, $file, $useAttachment = false, $defaultName = '', $maxSize = 2_097_152) argument
733 $file .= $name;
736 $fileexists = file_exists($file);
737 $fp = @fopen($file, "w");
742 chmod($file, $conf['fperm']);
803 * Search a file for matching lines
805 * This is probably not faster than file()+preg_grep() but less
806 * memory intensive because not the whole file needs to be loaded
809 * @param string $file The file to search
817 function io_grep($file, $pattern, $max = 0, $backref = false) argument
819 $fh = @fopen($file, 'r');
847 * Get size of contents of a file, for a compressed file the uncompressed size
850 * @param string $file filename path to file
851 * @return int size of file
855 function io_getSizeFile($file) argument
857 if (!file_exists($file)) return 0;
859 if (str_ends_with($file, '.gz')) {
860 $fp = @fopen($file, "rb");
867 } elseif (str_ends_with($file, '.bz2')) {
869 $bz = bzopen($file, "r");
881 $uncompressedsize = filesize($file);