Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. <?php
  2. // before you just copy and paste this logic please understand that there has already been a connection to said server
  3. // we are basically trying to find a specific file, in this case an svg image, by scanning the directory and looping
  4. // through until we find said file. Then we render that which will provide the actual path. This isn't meant as
  5. // a permanent fix for rendering files, this case images, but to check as thoroughly as possible if that actual
  6. // file exists. Change the resources_path_name to the specific path you would like to target.
  7.  
  8. // we pass a $path object through the function that we later call by doing listIt('path_name');
  9. function listIt($path) {
  10. $items = $path;
  11.  
  12. foreach($items as $item){
  13. if($item != "." AND $item != "..") {
  14. if (is_file($path . $item)) {
  15. // this is the file code for selected file
  16. } else {
  17. // this is the directory path
  18.  
  19. listIt($path . $item . "/");
  20. }
  21. }
  22. }
  23.  
  24. // this is a variable to access the 6th object in an array of objects, if you know which object you are trying to find
  25. // then just change this to that file placement
  26. // $resources = scandir($resources_directory[6]);
  27.  
  28. $startfolder=scandir($_SERVER['DOCUMENT_ROOT']);
  29. $startfolder=$_SERVER['DOCUMENT_ROOT'].'/resources_path_name';
  30. $files=array();
  31.  
  32.  
  33. foreach( new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $startfolder, RecursiveDirectoryIterator::KEY_AS_PATHNAME ), RecursiveIteratorIterator::CHILD_FIRST ) as $file => $info ) {
  34. if( $info->isFile() && $info->isReadable() ){
  35. $files[]=array('filename'=>$info->getFilename(),'path'=>realpath( $info->getPathname() ) );
  36. }
  37. }
  38. $svgimage = print_r($files[57]["path"],true);
  39. //this is for visually checking the path
  40.  
  41. //echo '<pre>',$svgimage,'</pre>';
  42. //die();
  43. //calling the function, as stated before, and passing a path from the variable of $startfolder
  44. //var_dump(listIt($startfolder));
  45. //die();
  46. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement