@@ -229,202 +229,4 @@ protected function getItem(string $filename): array|false
229229
230230 return $ data ;
231231 }
232-
233- /**
234- * Writes a file to disk, or returns false if not successful.
235- *
236- * @deprecated 4.6.1 Use `write_file()` instead.
237- *
238- * @param string $path
239- * @param string $data
240- * @param string $mode
241- */
242- protected function writeFile ($ path , $ data , $ mode = 'wb ' ): bool
243- {
244- if (($ fp = @fopen ($ path , $ mode )) === false ) {
245- return false ;
246- }
247-
248- flock ($ fp , LOCK_EX );
249-
250- $ result = 0 ;
251-
252- for ($ written = 0 , $ length = strlen ($ data ); $ written < $ length ; $ written += $ result ) {
253- if (($ result = fwrite ($ fp , substr ($ data , $ written ))) === false ) {
254- break ;
255- }
256- }
257-
258- flock ($ fp , LOCK_UN );
259- fclose ($ fp );
260-
261- return is_int ($ result );
262- }
263-
264- /**
265- * Deletes all files contained in the supplied directory path.
266- * Files must be writable or owned by the system in order to be deleted.
267- * If the second parameter is set to TRUE, any directories contained
268- * within the supplied base directory will be nuked as well.
269- *
270- * @deprecated 4.6.1 Use `delete_files()` instead.
271- *
272- * @param string $path File path
273- * @param bool $delDir Whether to delete any directories found in the path
274- * @param bool $htdocs Whether to skip deleting .htaccess and index page files
275- * @param int $_level Current directory depth level (default: 0; internal use only)
276- */
277- protected function deleteFiles (string $ path , bool $ delDir = false , bool $ htdocs = false , int $ _level = 0 ): bool
278- {
279- // Trim the trailing slash
280- $ path = rtrim ($ path , '/ \\' );
281-
282- if (! $ currentDir = @opendir ($ path )) {
283- return false ;
284- }
285-
286- while (false !== ($ filename = @readdir ($ currentDir ))) {
287- if ($ filename !== '. ' && $ filename !== '.. ' ) {
288- if (is_dir ($ path . DIRECTORY_SEPARATOR . $ filename ) && $ filename [0 ] !== '. ' ) {
289- $ this ->deleteFiles ($ path . DIRECTORY_SEPARATOR . $ filename , $ delDir , $ htdocs , $ _level + 1 );
290- } elseif (! $ htdocs || preg_match ('/^(\.htaccess|index\.(html|htm|php)|web\.config)$/i ' , $ filename ) !== 1 ) {
291- @unlink ($ path . DIRECTORY_SEPARATOR . $ filename );
292- }
293- }
294- }
295-
296- closedir ($ currentDir );
297-
298- return ($ delDir && $ _level > 0 ) ? @rmdir ($ path ) : true ;
299- }
300-
301- /**
302- * Reads the specified directory and builds an array containing the filenames,
303- * filesize, dates, and permissions
304- *
305- * Any sub-folders contained within the specified path are read as well.
306- *
307- * @deprecated 4.6.1 Use `get_dir_file_info()` instead.
308- *
309- * @param string $sourceDir Path to source
310- * @param bool $topLevelOnly Look only at the top level directory specified?
311- * @param bool $_recursion Internal variable to determine recursion status - do not use in calls
312- *
313- * @return array<string, array{
314- * name: string,
315- * server_path: string,
316- * size: int,
317- * date: int,
318- * relative_path: string,
319- * }>|false
320- */
321- protected function getDirFileInfo (string $ sourceDir , bool $ topLevelOnly = true , bool $ _recursion = false ): array |false
322- {
323- static $ filedata = [];
324-
325- $ relativePath = $ sourceDir ;
326- $ filePointer = @opendir ($ sourceDir );
327-
328- if (! is_bool ($ filePointer )) {
329- // reset the array and make sure $sourceDir has a trailing slash on the initial call
330- if ($ _recursion === false ) {
331- $ filedata = [];
332-
333- $ resolvedSrc = realpath ($ sourceDir );
334- $ resolvedSrc = $ resolvedSrc === false ? $ sourceDir : $ resolvedSrc ;
335-
336- $ sourceDir = rtrim ($ resolvedSrc , DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR ;
337- }
338-
339- // Used to be foreach (scandir($sourceDir, 1) as $file), but scandir() is simply not as fast
340- while (false !== $ file = readdir ($ filePointer )) {
341- if (is_dir ($ sourceDir . $ file ) && $ file [0 ] !== '. ' && $ topLevelOnly === false ) {
342- $ this ->getDirFileInfo ($ sourceDir . $ file . DIRECTORY_SEPARATOR , $ topLevelOnly , true );
343- } elseif (! is_dir ($ sourceDir . $ file ) && $ file [0 ] !== '. ' ) {
344- $ filedata [$ file ] = $ this ->getFileInfo ($ sourceDir . $ file );
345-
346- $ filedata [$ file ]['relative_path ' ] = $ relativePath ;
347- }
348- }
349-
350- closedir ($ filePointer );
351-
352- return $ filedata ;
353- }
354-
355- return false ;
356- }
357-
358- /**
359- * Given a file and path, returns the name, path, size, date modified
360- * Second parameter allows you to explicitly declare what information you want returned
361- * Options are: name, server_path, size, date, readable, writable, executable, fileperms
362- * Returns FALSE if the file cannot be found.
363- *
364- * @deprecated 4.6.1 Use `get_file_info()` instead.
365- *
366- * @param string $file Path to file
367- * @param list<string>|string $returnedValues Array or comma separated string of information returned
368- *
369- * @return array{
370- * name?: string,
371- * server_path?: string,
372- * size?: int,
373- * date?: int,
374- * readable?: bool,
375- * writable?: bool,
376- * executable?: bool,
377- * fileperms?: int
378- * }|false
379- */
380- protected function getFileInfo (string $ file , $ returnedValues = ['name ' , 'server_path ' , 'size ' , 'date ' ]): array |false
381- {
382- if (! is_file ($ file )) {
383- return false ;
384- }
385-
386- if (is_string ($ returnedValues )) {
387- $ returnedValues = explode (', ' , $ returnedValues );
388- }
389-
390- $ fileInfo = [];
391-
392- foreach ($ returnedValues as $ key ) {
393- switch ($ key ) {
394- case 'name ' :
395- $ fileInfo ['name ' ] = basename ($ file );
396- break ;
397-
398- case 'server_path ' :
399- $ fileInfo ['server_path ' ] = $ file ;
400- break ;
401-
402- case 'size ' :
403- $ fileInfo ['size ' ] = filesize ($ file );
404- break ;
405-
406- case 'date ' :
407- $ fileInfo ['date ' ] = filemtime ($ file );
408- break ;
409-
410- case 'readable ' :
411- $ fileInfo ['readable ' ] = is_readable ($ file );
412- break ;
413-
414- case 'writable ' :
415- $ fileInfo ['writable ' ] = is_writable ($ file );
416- break ;
417-
418- case 'executable ' :
419- $ fileInfo ['executable ' ] = is_executable ($ file );
420- break ;
421-
422- case 'fileperms ' :
423- $ fileInfo ['fileperms ' ] = fileperms ($ file );
424- break ;
425- }
426- }
427-
428- return $ fileInfo ;
429- }
430232}
0 commit comments