Jump to content
php.lv forumi

faila izmera pieliksana


Snaip3Rs

Recommended Posts

Funkcija ir aritmētiskā dalīšana. To apzīmē ar slīpsvītru /

izmers_kilobaitos = izmers_baitos / 1024;

izmers_megabaitos = izmers_kilobaitos / 1024;

īsumā šādi:

$mervienibas = Array('B', 'kB', 'MB', 'GB', 'TB'); //domājams, ka par terabaitu lielāku failu pagaidām Tev nebūs.
$izmers = funkcija_kas_dabu_izmeru_baitos();
$mervienibas_indekss = 0; //Uzskatam, ka fails ir pietiekami mazs, lai būtu mazāks par 1024B.
while($izmers > 1024){
$mervienibas_indekss++;
$izmers=$izmers/1024;
}
if($mervienibas_indekss > 0){
//tātad ir bijusi dalīšana un vajag noapaļot līdz smukam izskatam, teiksim, divām zīmēm aiz punkta
$izmers = round($izmers,2);
}
echo 'Izmērs: ' . $izmers . ' ' . $mervienibas[$mervienibas_indekss];

Link to comment
Share on other sites

Paldies ka palīdzēji bet man nesanāk vari salikt to kodu kopā ar failu!

fails ko liek iznešanai

<p><a href="countdownloads.php">Download File</a><br />
<?php
$myFile = "counter.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
echo $theData;
fclose($fh);
?> lejuplades<br /></p>

fails kurā liek failu

<?php
$myFile = "counter.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
$theData = $theData + 1;
$myFile = "counter.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $theData);
fclose($fh);
header("Location: deathrun_lv_zone.rar");
?>

lūdzu palīdzi-Aleksej jo citi tur tik kautko stast bet nerada ka to izdarīt!

Link to comment
Share on other sites

Atvaino aleksej es ieliku nepareizo kodu tur es visu meginaju un bija izdzisis!

<p><a href="countdownloads.php">Download File</a><br />
<?php
$myFile = "counter.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
echo $theData;
fclose($fh);
?> lejuplades<br /></p>
<p><?php
echo filesize("deathrun_lv_zone.rar");
?> Izmers<br /></p>

Link to comment
Share on other sites

Liels paldies vis strādā, bet ir viens "bet" cilvēki jau neliek vienu failu lejuplādēt tam nav jēga es jau vēlos likt vairākus failus lejuplādēt, bet nācu pie secinājuma ja es vēlos vairākus failus man jātaisa daudzas counter direktorijas tapē labāk nevarētu kautko savadāk izdarīt jo katram failam vajadzētu savu txt dokumentu gur glabāt. Ko jūs ieteiktu lai nevajadzētu taisīt txt failus vairākus!

 

Izvada

<table>
<tr>
<td>
<a href="countdownloads.php">Download File</a>
</td>
<td>
<?php
$myFile = "counter.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
echo $theData;
fclose($fh);
?> 
lejuplades
</td>
<td>
<?php
$mervienibas = Array('B', 'kB', 'MB', 'GB', 'TB'); //dom?jams, ka par terabaitu liel?ku failu pagaid?m Tev neb?s. 
$izmers=filesize('mani_faili/deathrun_lv_zone.rar');  
$mervienibas_indekss = 0; //Uzskatam, ka fails ir pietiekami mazs, lai b?tu maz?ks par 1024B. 
while($izmers > 1024){ 
$mervienibas_indekss++; 
$izmers=$izmers/1024; 
} 
if($mervienibas_indekss > 0){ //t?tad ir bijusi dal??ana un vajag noapa?ot l?dz smukam izskatam, teiksim, div?m z?m?m aiz punkta 
$izmers = round($izmers,0); 
} 
echo '' . $izmers . ' ' . $mervienibas[$mervienibas_indekss];
?> 
</td>
<td>
30-07-2009
</td>
</tr>
</br>
<tr>
<td>
<a href="countdownloads.php">Download File</a>
</td>
<td>
<?php
$myFile = "counter.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
echo $theData;
fclose($fh);
?> 
lejuplades
</td>
<td>
<?php
$mervienibas = Array('B', 'kB', 'MB', 'GB', 'TB'); //dom?jams, ka par terabaitu liel?ku failu pagaid?m Tev neb?s. 
$izmers=filesize('mani_faili/cs_backround_maker_30_install.exe');  
$mervienibas_indekss = 0; //Uzskatam, ka fails ir pietiekami mazs, lai b?tu maz?ks par 1024B. 
while($izmers > 1024){ 
$mervienibas_indekss++; 
$izmers=$izmers/1024; 
} 
if($mervienibas_indekss > 0){ //t?tad ir bijusi dal??ana un vajag noapa?ot l?dz smukam izskatam, teiksim, div?m z?m?m aiz punkta 
$izmers = round($izmers,0); 
} 
echo '' . $izmers . ' ' . $mervienibas[$mervienibas_indekss];
?> 
</td>
<td>
30-07-2009
</td>
</tr>
</table>

 

glabāšanas funkcija

<?php
$myFile = "counter.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
$theData = $theData + 1;
$myFile = "counter.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $theData);
fclose($fh);
header("Location: mani_faili/deathrun_lv_zone.rar");
?>
<?php
$myFile = "counter.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
$theData = $theData + 1;
$myFile = "counter.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $theData);
fclose($fh);
header("Location: mani_faili/cs_backround_maker_30_install.exe");
?>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...