Jump to content

can't extract path from query


jac.kock

Recommended Posts

hello people,

 

I need some help with my code, i made a form to display all files in a folder and de files in the subfolder(S) of teh main folder!

 

I can get the file name from the query and de full path of the query :)

 

but i can't seem to get the folder and subfolder path from this query :(

 

My code of the file :

<?php
/*
Copyright by j.kock, pc-hulp-online
[email protected]
http://www.pc-hulp-online.nl
*/
?>
<script language="javascript">
function check()
{
if(document.XXXXXXX.XXXXXXX.value=="")
{
 alert("Leeg veld niet toegestaan");
 return;
}
else
{
 this.edit_user.submit();
}
}
</script>
<?php
if($_POST['Submit'])
{
}
?>
<table align="center" width="98%">
 <tr>
<th></th>
 </tr>
 <tr>
<th align="center" class="text">Verwijderen upload bestanden</th>
 </tr>
 <tr>
<th><hr /></th>
 </tr>
   <?php
if($_POST['Submit'])
{
  if($res)
  {
 echo '<tr><th align="center">Succesvol geüpdate</th></tr>';
  }
  else
  {
 echo '<tr><th align="center">Error updating</th></tr>';
  }
}
?>
 <tr>
<td>
  <form name="del_upload" action="?admin=del_upload" method="post" enctype="multipart/form-data">
 <table width="100%" align="center">
   <tr>
  <td width="25%" align="left" bgcolor="#007FFF">
 bestand:
  </td>
  <td width="25%" align="left" bgcolor="#007FFF">
 Folder:
  </td>
  <td width="50%" align="left" bgcolor="#007FFF">
 Verwijder:
  </td>
   </tr>
   <?php
/**
 * Get an array that represents directory tree
 * @param string $directory	 Directory path
 * @param bool $recursive		 Include sub directories
 * @param bool $listDirs		 Include directories on listing
 * @param bool $listFiles		 Include files on listing
 * @param regex $exclude		 Exclude paths that matches this regex
 */
   function directoryToArray($directory, $recursive = true, $listDirs = false, $listFiles = true, $exclude = '') {
    $arrayItems = array();
    $skipByExclude = false;
    $handle = opendir($directory);
    if ($handle) {
	    while (false !== ($file = readdir($handle))) {
	    preg_match("/(^(([\.]){1,2})$|(\.(svn|git|md))|(Thumbs\.db|\.DS_STORE))$/iu", $file, $skip);
	    if($exclude){
		    preg_match($exclude, $file, $skipByExclude);
	    }
	    if (!$skip && !$skipByExclude) {
		    if (is_dir($directory. DIRECTORY_SEPARATOR . $file)) {
			    if($recursive) {
				    $arrayItems = array_merge($arrayItems, directoryToArray($directory. DIRECTORY_SEPARATOR . $file, $recursive, $listDirs, $listFiles, $exclude));
			    }
			    if($listDirs){
				    $file = $directory . DIRECTORY_SEPARATOR . $file;
				    $arrayItems[] = $file;
			    }
		    } else {
			    if($listFiles){
				    $file = $directory . DIRECTORY_SEPARATOR . $file;
				    $arrayItems[] = $file;
			    }
		    }
	    }
    }
    closedir($handle);
    }
    return $arrayItems;
   }
$dirs=directoryToArray("upload");
  for($dd = 0; $dirs[$dd] <> ""; $dd++)
  {
 $uploadfile1=explode(DIRECTORY_SEPARATOR,$dirs[$dd]);
 $count=count($uploadfile1);
   $path="";
   $cd=0;

 for($cd > $count; $uploadfile1[$cd]; $cd++)
 {
   $path=$path.$uploadfile1[$cd]."/";
 }

  $file=$uploadfile1[count($uploadfile1)-1];
  ?>
 <tr>
 <td width="25%" align="left">
  <? echo $file; ?>
 </td>
 <td width="25%" align="left">
  <? echo $path; ?>
 </td>
 <td width="50%" align="left">
  <? echo $dirs[$dd]; ?>
 </td>
 </tr>
  <?
  }
   ?>
   <tr>
  <td colspan="3" align="center">
 <!--<input type="submit" name="Submit" value="Opslaan" >-->
 <!--<input type="submit" name="Submit" value="Opslaan" onclick="check();">-->
  </td>
   </tr>
 </table>
  </form>
</td>
 </tr>
</table>

 

the output looks like this:

 

bestand: Folder: Verwijder: no_avatar.gif upload/users/no_avatar.gif/ upload/users/no_avatar.gif Picture 4.jpg upload/users/Picture 4.jpg/ upload/users/Picture 4.jpg eula.txt upload/eula.txt/ upload/eula.txt README.txt upload/README.txt/ upload/README.txt tmp.txt upload/tmp.txt/ upload/tmp.txt blank.txt upload/blank.txt/ upload/blank.txt empty.txt upload/empty.txt/ upload/empty.txt intro.txt upload/intro.txt/ upload/intro.txt nope.jpg upload/images/category_images/nope.jpg/ upload/images/category_images/nope.jpg nope.jpg upload/images/product_images/nope.jpg/ upload/images/product_images/nope.jpg add_menu.php upload/images/product_images/admin/add_menu.php/ upload/images/product_images/admin/add_menu.php add_page.php upload/images/product_images/admin/add_page.php/ upload/images/product_images/admin/add_page.php add_submenu.php upload/images/product_images/admin/add_submenu.php/ upload/images/product_images/admin/add_submenu.php add_upload.php upload/images/product_images/admin/add_upload.php/ upload/images/product_images/admin/add_upload.php clients.php upload/images/product_images/admin/clients.php/ upload/images/product_images/admin/clients.php del_menu.php upload/images/product_images/admin/del_menu.php/ upload/images/product_images/admin/del_menu.php del_page.php upload/images/product_images/admin/del_page.php/ upload/images/product_images/admin/del_page.php del_submenu.php upload/images/product_images/admin/del_submenu.php/ upload/images/product_images/admin/del_submenu.php

 

i want that in the 2e col it shows the path like: upload/images/category_images/

 

can someone tell me what i'm doing wrong?

 

thnx all,

Link to comment
https://forums.phpfreaks.com/topic/274204-cant-extract-path-from-query/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.