Šta je novo?

PHP - gde sam zabrljala? Pomagajte!

Psyche

Slavan
Učlanjen(a)
02.07.2005
Poruke
56
Poena
309
Uzela sam da prepravljam jednu skriptu i sve je fino proslo sem sledeceg.
Kraci opsi iste: download menager, fajlovi se jednostavno ubacuju preko ftp-a u neki direktorijum, a skripta automatski izlistava naziv, velicinu, ekstenziju itd.

Skriptu mozete pogledati na - http://stud.usv.ro/~vlad_l/personal/
Kao sto vidite ona ima jedinstvenu tabelu sa stavkama: ico, nume...


Ja imam root, u njemu 30-ak foldera, a svaki folder sadrzi izvestan broj fajlova.
Podelila sam to u dva dela. Direktorijumi mi se izlistavaju ovako:

Kod:
<!-- START PRINTING THE DIRECTORY'S CONTENTS -->
<?php

	// variable used to select row background color
	$j = -1;

	// read each element of the directories array
	foreach($directoare as $key => $director) {

		// ignore the parent directory '..' when printing the contents of the root directory
		if (!strcmp($director, "..") && !strcmp($dirpath, ".")) {
			continue;
		}

		// variable used to select row background color
		$j++;

		// array to keep each directory's stats
		$dta = stat($director);

		// the directories are treated this way...
		// except '..' which has a different icon from the other directories
		  if (strcmp($director, "..")) {

                echo "<table class=\"main_table\" cellspacing=\"2\" align=\"center\" cellpadding=\"0\">";
                echo "<tr>";
                echo "<td width=\"20\" align=\"center\" class=\"tab_header_cell\">X</td>";
                echo "<td width=\"360\" align=\"center\" class=\"tab_header_cell\">Naziv predmeta</td>";
                echo "<td width=\"110\" align=\"center\" class=\"tab_header_cell\">Broj dokumenata</td>";
                echo "<td width=\"110\" align=\"center\" class=\"tab_header_cell\">Poslednja izmena</td>";
                echo "</tr>";
?>
<?php
			echo "<tr bgcolor='".$color[$j%2]."' height='20'>";
			if ($SHOW_ICON) {
				echo "<td align=\"center\"><img src=\"".$imgdir."dir.gif\"></td>";
			}
			echo "<td align=\"left\"><a href=\"index.php?dirpath=$dirpath/".str_replace('&', '*', $director)."&order=".$varget['order']."\">[".$director."]</a>";
			if (((time() - $dta[9]) / 1E+5) < $new_period) {
				echo " <span class=\"small_red_text\">$msg_new</span>";
			}
			echo "</td>";

                        if ($SHOW_SIZE) {
				echo "<td align=\"right\"><span class=\"text\">[".broj_fajlova($director)."]</span></td>";
			}

                        if ($SHOW_MODIFIED) {
				echo "<td align=\"center\"><span class=\"text\">".date("d.m.y u H:i:s", $dta[9])."</td>";
			}
			echo "</tr></table>";

                        clearstatcache();

}

a fajlovi ovako:

Kod:
  else
        {
                  echo "<table class=\"main_table\" cellspacing=\"2\" align=\"center\" cellpadding=\"0\">";
                  echo "<tr>";
                  echo "<td width=\"20\" align=\"center\" class=\"tab_header_cell\">X</td>";
                  echo "<td width=\"280\" align=\"center\" class=\"tab_header_cell\">Naziv okumenta</td> ";
                  echo "<td width=\"50\" align=\"center\" class=\"tab_header_cell\">Format</td>";
                  echo "<td width=\"130\" align=\"center\" class=\"tab_header_cell\">Opis Formata</td>";
                  echo "<td width=\"60\" align=\"center\" class=\"tab_header_cell\">Velicina</td>";
                  echo "<td width=\"110\" align=\"center\" class=\"tab_header_cell\">Poslednja izmena</td>";
                  echo "</tr>";


			echo "<tr bgcolor='".$color[$j%2]."' height='20'>";
                     	echo "<td align=\"center\"><img src=\"".$imgdir."dir.gif\"></td>";
			echo "<td align=\"left\"><a href=\"index.php?dirpath=$dirpath/".str_replace('&', '*', $director)."&order=".$varget['order']."\">[".$director."]</a>";
			echo "</td>";
                        echo "<td align=\"right\"><span class=\"text\">[]</span></td>";
			echo "<td align=\"right\"><span class=\"text\">[]</span></td>";
			echo "<td align=\"right\"><span class=\"text\">[]</span></td>";
                    	echo "<td align=\"center\"><span class=\"text\">".date("d.m.y u H:i:s", $dta[9])."</td>";
			echo "</tr>";
	}
?>
	<?php
	// read each element of the files array
	foreach($fisiere as $key => $file) {

		$j++;

		// array to keep each directory's stats
		$dta = stat($file);

		// split the filename into name and extension
		$split_name_ext = explode(".", $file);

		// store the file extension
		$extensie = (count($split_name_ext)-1 != 0) ? $split_name_ext[count($split_name_ext)-1] : "";

		// store the lowercased extenosion
		$lextensie = strtolower($extensie);

		// if there is a custom icon and descrpition for this type of files
		// use them instead of the default ones
		if (array_key_exists($lextensie, $exts)) {
			$descriere = $exts[$lextensie][0];
			$iconita = $exts[$lextensie][1];
		} else {
			// these are the default icon and description
			$descriere = "";
			$iconita = "unknown.gif";
		}

		echo "<tr bgcolor='".$color[$j%2]."' height='20'>";
		// print the icon
		if ($SHOW_ICON) {
			echo "<td align=\"center\"><img src=\"".$imgdir."$iconita\"></td>";
		}

		// print the filename
		if (in_array($lextensie, $not_to_be_dloaded)) {
			// for the files that should not be downloaded use a direct link
			echo "<td align=\"left\"><span class=\"file_text\"><a href=\"$dirpath/$file\"><span class=\"file_text\">".$split_name_ext[0];
		} else {
			// for the files that should be downloaded use the 'download.php' script
			echo "<td align=\"left\"><span class=\"file_text\"><a href=\"download.php?fname=".str_replace('&', '*', $dirpath."/".$file)."\" onmouseover=\"MM_displayStatusMsg('')\" onmouseout=\"MM_displayStatusMsg('$msg_status')\"><span class=\"file_text\">".$split_name_ext[0];
		}
		for($i = 1; $i < count($split_name_ext) - 1; $i++) {
			echo (".$split_name_ext[$i]");
		}
		echo "</a></span>";
		// print '$msg_new' for new files
		if ( ((time() - $dta[9]) / 1E+5) < $new_period) {
			echo " <span class=\"small_red_text\">$msg_new</span> ";
		}
		echo "</td>";

		// print the extension
		echo "<td align=\"right\"><span class=\"text\">";
		echo $extensie;
		echo "</td>";

                // print the file type description
		if ($SHOW_DESCRIPTION) {
			echo "<td align=\"right\"><span class=\"text\">".$descriere."</span></td>";
		}

		// print the file size
		if ($SHOW_SIZE) {
			echo "<td align=\"right\"><span class=\"text\">";
			printf("<span class=\"text\">%.2f KB</span>", $dta[7]/1024);
			echo "</span></td>";
		}


                // print the date the file was last modified
		if ($SHOW_MODIFIED) {
			echo "<td align=\"center\"><span class=\"text\">".date("d.m.y u H:i:s", $dta[9])."</td>";
		}

		echo "</tr>";

		// clear the stats of the entry
		clearstatcache();
	}
?>
</table>

<!-- STOP PRINTING THE DIRECTORY'S CONTENTS -->

Deo sa fajlovima po ulasku u odredjeni dir prikazuje se korektno.
Gore je zaglavlje sa stavkama: Naziv dokumenta, Format, Opis formata...
i poredjani su jedni ispod drugih.
Header se pojavljuje samo na vrhu.


PROBLEM je deo koji mi ispisuje direktorijume jer mi izbaci header, pa ispise naziv direktorijuma, broj dokumenata i kad je modifikovano, pa izbaci OPET header pa naziv sledeceg u nizu itd.
Kako to da izbegnem. Dakle na vrhu ispise samo jednom header i onda lista direktorijuma ispod.
Hvala!
 
Uzasno je nepregledno........ali ako mogu nekako da ti budem od koristi, vidi da deo gde kreiras header nije u nekom foreach-u, izbaci ga napolje.....pricam napamet, ali u tome je verovatno zez......inace ne radim u php-u, ali je sve to isto ;)
Pozdrav.
 
Jeste, ali ne znam kako da ga izbacim, mislim ne smem jer se desavaju gluposti. Dakle, suzili smo problem na:
Kod:
<?php

$j = -1;

[COLOR=Red]foreach($directoare as $key => $director)[/COLOR]

{

if (!strcmp($director, "..") && !strcmp($dirpath, ".")) 
{
continue;
}

$j++;

$dta = stat($director);

if (strcmp($director, ".."))

{

[COLOR=Red]echo "<table class=\"main_table\" cellspacing=\"2\" align=\"center\" cellpadding=\"0\">";
echo "<tr>";
echo "<td width=\"20\" align=\"center\" class=\"tab_header_cell\">X</td>";
echo "<td width=\"360\" align=\"center\" class=\"tab_header_cell\">Naziv predmeta</td>";
echo "<td width=\"110\" align=\"center\" class=\"tab_header_cell\">Broj dokumenata</td>";
echo "<td width=\"110\" align=\"center\" class=\"tab_header_cell\">Poslednja izmena</td>";
echo "</tr>";[/COLOR]
?>

<?php
echo "<tr bgcolor='".$color[$j%2]."' height='20'>";
if ($SHOW_ICON) {
echo "<td align=\"center\"><img src=\"".$imgdir."dir.gif\"></td>";

}

echo "<td align=\"left\"><a href=\"index.php?dirpath=$dirpath/".str_replace('&', '*', $director)."&order=".$varget['order']."\">[".$director."]</a>";
if (((time() - $dta[9]) / 1E+5) < $new_period) {
echo " <span class=\"small_red_text\">$msg_new</span>";

}

echo "</td>";
if ($SHOW_SIZE) {
echo "<td align=\"right\"><span class=\"text\">[".broj_fajlova($director)."]</span></td>";
}
if ($SHOW_MODIFIED) {
echo "<td align=\"center\"><span class=\"text\">".date("d.m.y u H:i:s", $dta[9])."</td>";

}

echo "</tr></table>";

clearstatcache();

}


Pa ja uopste ne znam PHP niti bilo koji programski jezik.
Ne znam kako se upustam u sve to :D
 
Poslednja izmena:
Pa to crveno izbaci iznad crvenog foreach-a
Cekaj a to sto ti koristis je originalni skript........odakle ti ideja da ga menjas
 
Ma ne moze tako, nebitno, htela sam da prilagodim skriptu svojim potrebama ali posto ne ide nema veze :)

A gore napisani kod je prepravljen kod. Original bi isao ovako:
Kod:
<!-- START PRINTING THE DIRECTORY'S CONTENTS -->
<table class="main_table" cellspacing="2" align="center" cellpadding="0">
	<?php
		if ($SHOW_TAB_HEADER_ROW) {
	?>
	<tr>
		<?php if ($SHOW_ICON) {?>
			<td width="30" align="center" class="tab_header_cell"><?php echo $msg_ico; ?></td>
		<?php } ?>

		<td width="200" align="center" class="tab_header_cell" <?php echo "onclick=\"window.location='index.php?dirpath=$jsdir&order=".(1 - $varget['order'])."'\"";?>>
		<?php echo $msg_name; ?> <?php echo $sageata; ?></td>

		<td width="40" align="center" class="tab_header_cell"><?php echo $msg_ext; ?></td>

		<?php if ($SHOW_SIZE) {?>
			<td width="80" align="center" class="tab_header_cell"><?php echo $msg_size; ?></td>
		<?php } ?>

		<?php if ($SHOW_MODIFIED) {?>
			<td width="110" align="center" class="tab_header_cell"><?php echo $msg_modified; ?></td>
		<?php } ?>

		<?php if ($SHOW_DESCRIPTION) {?>
			<td width="150" align="center" class="tab_header_cell"><?php echo $msg_description; ?></td>
		<?php } ?>
	</tr>
	<?php
		} else {
	?>
	<tr>
		<?php if ($SHOW_ICON) {?>
			<td width="30"></td>
		<?php } ?>

		<td width="200"></td>
		<td width="40"></td>

		<?php if ($SHOW_SIZE) {?>
			<td width="80"></td>
		<?php } ?>

		<?php if ($SHOW_MODIFIED) {?>
			<td width="110"></td>
		<?php } ?>

		<?php if ($SHOW_DESCRIPTION) {?>
			<td width="150"></td></tr>
		<?php } ?>
	<?php
		}
	?>
<?php

	// variable used to select row background color
	$j = -1;

	// read each element of the directories array
	foreach($directoare as $key => $director) {

		// ignore the parent directory '..' when printing the contents of the root directory
		if (!strcmp($director, "..") && !strcmp($dirpath, ".")) {
			continue;
		}

		// variable used to select row background color
		$j++;

		// array to keep each directory's stats
		$dta = stat($director);

		// the directories are treated this way...
		// except '..' which has a different icon from the other directories
		if (strcmp($director, "..")) {
			echo "<tr bgcolor='".$color[$j%2]."' height='20'>";
			if ($SHOW_ICON) {
				echo "<td align=\"center\"><img src=\"".$imgdir."dir.gif\"></td>";
			}
			echo "<td align=\"left\"><a href=\"index.php?dirpath=$dirpath/".str_replace('&', '*', $director)."&order=".$varget['order']."\"><span class=\"dir_text\">[".$director."]</span></a>";
			if (((time() - $dta[9]) / 1E+5) < $new_period) {
				echo " <span class=\"small_red_text\">$msg_new</span>";
			}
			echo "</td>";
			echo "<td align=\"right\"></td>";
			if ($SHOW_SIZE) {
				echo "<td align=\"right\"><span class=\"text\"><DIR></span></td>";
			}
			if ($SHOW_MODIFIED) {
				echo "<td align=\"right\"><span class=\"text\">".date("d.m.Y H:i", $dta[9])."</td>";
			}
			if ($SHOW_DESCRIPTION) {
				echo "<td align=\"right\"></td>";
			}
			echo "</tr>";
		} else {
			echo "<tr bgcolor='".$color[$j%2]."' height='20'>";
			if ($SHOW_ICON) {
				echo "<td align=\"center\"><img src=\"".$imgdir."back.gif\"></td>";
			}
			echo "<td align=\"left\"><a href=\"index.php?dirpath=".dirname($dirpath)."&order=".$varget['order']."\"><span class=\"dir_text\">[".$director."]</span></a></td>";
			echo "<td align=\"right\"></td>";
			if ($SHOW_SIZE) {
				echo "<td align=\"right\"><span class=\"text\"><DIR></span></td>";
			}
			if ($SHOW_MODIFIED) {
				echo "<td align=\"right\"><span class=\"text\">".date("d.m.Y H:i", $dta[9])."</td>";
			}
			if ($SHOW_DESCRIPTION) {
				echo "<td align=\"right\"></td>";
			}
			echo "</tr>";
		}
		// clear the stats of the entry
		clearstatcache();
	}


	// read each element of the files array
	foreach($fisiere as $key => $file) {

		$j++;

		// array to keep each directory's stats
		$dta = stat($file);

		// split the filename into name and extension
		$split_name_ext = explode(".", $file);

		// store the file extension
		$extensie = (count($split_name_ext)-1 != 0) ? $split_name_ext[count($split_name_ext)-1] : "";

		// store the lowercased extenosion
		$lextensie = strtolower($extensie);

		// if there is a custom icon and descrpition for this type of files
		// use them instead of the default ones
		if (array_key_exists($lextensie, $exts)) {
			$descriere = $exts[$lextensie][0];
			$iconita = $exts[$lextensie][1];
		} else {
			// these are the default icon and description
			$descriere = "";
			$iconita = "unknown.gif";
		}

		echo "<tr bgcolor='".$color[$j%2]."' height='20'>";
		// print the icon
		if ($SHOW_ICON) {
			echo "<td align=\"center\"><img src=\"".$imgdir."$iconita\"></td>";
		}

		// print the filename
		if (in_array($lextensie, $not_to_be_dloaded)) {
			// for the files that should not be downloaded use a direct link
			echo "<td align=\"left\"><a href=\"$dirpath/$file\"><span class=\"text\">".$split_name_ext[0];
		} else {
			// for the files that should be downloaded use the 'download.php' script
			echo "<td align=\"left\"><a href=\"download.php?fname=".str_replace('&', '*', $dirpath."/".$file)."\" onmouseover=\"MM_displayStatusMsg('')\" onmouseout=\"MM_displayStatusMsg('$msg_status')\"><span class=\"text\">".$split_name_ext[0];
		}
		for($i = 1; $i < count($split_name_ext) - 1; $i++) {
			echo (".$split_name_ext[$i]");
		}
		echo "</span></a>";
		// print '$msg_new' for new files
		if ( ((time() - $dta[9]) / 1E+5) < $new_period) {
			echo " <span class=\"small_red_text\">$msg_new</span> ";
		}
		echo "</td>";

		// print the extension
		echo "<td align=\"right\"><span class=\"text\">";
		echo $extensie;
		echo "</td>";

		// print the file size
		if ($SHOW_SIZE) {
			echo "<td align=\"right\"><span class=\"text\">";
			printf("<span class=\"text\">%.2f KB</span>", $dta[7]/1024);
			echo "</span></td>";
		}

		// print the date the file was last modified
		if ($SHOW_MODIFIED) {
			echo "<td align=\"right\"><span class=\"text\">".date("d.m.Y H:i", $dta[9])."</td>";
		}

		// print the file type description
		if ($SHOW_DESCRIPTION) {
			echo "<td align=\"right\"><span class=\"text\">".$descriere."</span></td>";
		}

		echo "</tr>";

		// clear the stats of the entry
		clearstatcache();
	}
?>

</table>
<!-- STOP PRINTING THE DIRECTORY'S CONTENTS -->
			<?php
				}
			?>
 
Problem je sto kad crveni deo izbacim iznad foreach onda na fajl stranici imam dva headera i tablice 1 i tablice, jer header treba da stoji ispod
if (strcmp($director, "..")) {
 
Grrrrr, na domak sam resenja.
Dakle:

if (ako je u www. mojdomen. com/download])
{

echo "<table class=\"main_table\" cellspacing=\"2\" align=\"center\" cellpadding=\"0\">";
echo "<tr>";
echo "<td width=\"20\" align=\"center\" class=\"tab_header_cell\">X</td>";
echo "<td width=\"360\" align=\"center\" class=\"tab_header_cell\">Naziv predmeta</td>";
echo "<td width=\"110\" align=\"center\" class=\"tab_header_cell\">Broj dokumenata</td>";
echo "<td width=\"110\" align=\"center\" class=\"tab_header_cell\">Poslednja izmena</td>";
echo "</tr>";
}
else
{
echo "";
}




Jos samo neko da mi kaze koju funkciju da upotrebim, znam putanju znam sve, znaci samo funkcija. Ako se nalazim u download direktorijumu stampa ono, ako u bilo kom njegovom poddirektorijumu ostavlja prazno. Thanx!!!!!!
 
Poslednja izmena:
Nazad
Vrh Dno