Popis: Kalkulačka, kde vložíte veľkosť súboru a rýchlosť sťahovania v akejkoľvek jednotke, a vypočíta vám čas :) Časť kódu, kde by sa mal čas aj dynamicky "odpočitávať" som preskočil, keďže bol pre mňa časovo náročný a menej podstatný. Musím podotknúť, že je matematicky jemne nepresná (zatiaľ nezistený dôvod, možno zle nastavené konštanty...)
Kód:
scripts.php; časť "ETACALC"; formulár
<a id="show_id_1" onclick="document.getElementById('spoiler_id_1').style.display=''; document.getElementById('show_id_1').style.display='none';" class="link">
[ETA kalulačka]</a>
<span id="spoiler_id_1" style="display: none"><a onclick="document.getElementById('spoiler_id_1').style.display='none'; document.getElementById('show_id_1').style.display='';" class="link"><strike>[ETA kalulačka]</strike></a><br>
<?php
if (isset($_GET['show']) && $_GET['show'] == "ETA")
{
echo '<script>document.getElementById('spoiler_id').style.display=''; document.getElementById('show_id').style.display='none';</script>';
if (isset($_SESSION['Time']) && $_GET['results'] == "on")
{
if ($_SESSION['refresh'] == "1")
{
//Dynamic
echo "
<br><center>Výsledok:<div id=\"ETA\">
<span id=time></span>
</div></center><br>
";
}
else
{
//Static
echo " <br><center>Výsledok:<div id=\"ETA\"> ";
$hours = floor($_SESSION['Time'] / 3600);
$mins = floor(($_SESSION['Time'] - ($hours*3600)) / 60);
$secs = floor($_SESSION['Time'] % 60);
if ($hours < 1) echo($mins.'m : '.$secs.'s');
if ($hours >= 1) echo($hours.'h : '.$mins.'m');
echo " </div></center><br> ";
}
}
else
{
echo "!isset time or results not on <br>";
echo $_GET['results'];
echo "<br>";
echo $_SESSION['Time'];
}
}
? >
<form name="ETAcalc" action="scripts/ETAcalc.php" method="post">
<table border="0">
<tr>
<td>Veľkosť dát</td>
<td><input type="text" name="data" size="8">
<select name="dataType">
<option value="Kb">Kbit</option>
<option value="KB">KByte</option>
<option value="Mb">Mbit</option>
<option value="MB">MByte</option>
</select>
</td>
</tr>
<tr>
<td>Rýchlosť sťahovania</td>
<td>
<input type="text" name="speed" size="8">
<select name="speedType">
<option value="Kbps">Kbps</option>
<option value="KBs">KB/s</option>
<option value="Mbps">Mbps</option>
<option value="MBs">MB/S</option>
</select>
</td>
</tr>
<tr>
<td>Obnovovať čas?</td>
<!--<input type="hidden" name="refresh" value="0">-->
<td><input type="checkbox" name="refresh" value="1" <?php if ($_SESSION['refresh'] == "1") echo 'checked'; ? >> //Dočasne nefunkčné</td>
</tr>
</table>
<input type="submit" value="Vypočítať">
</form>
</span><br>
scripts/ETAcalc.php; skript
<?php
session_start();
if(!isset($_POST['data']) || !isset($_POST['speed']))
{
unset($r);
global $r;
$r="400";
header("Location: ../page.php?p=error");
die();
}
else
{
$data = $_POST['data'];
$dataType = $_POST['dataType'];
$speed = $_POST['speed'];
$speedType = $_POST['speedType'];
$_SESSION['refresh'] = $_POST['refresh'];
switch($dataType)
{
case 'Kb':
$dataTypeOperator = "1.024";
break;
case 'KB':
$dataTypeOperator = "8.192";
break;
case 'Mb':
$dataTypeOperator = "1024";
break;
case 'MB':
$dataTypeOperator = "8192";
break;
}
switch($speedType)
{
case 'Kbps':
$speedTypeOperator = "0.9765625";
break;
case 'KBs':
$speedTypeOperator = "0.78125";
break;
case 'Mbps':
$speedTypeOperator = "976.5625";
break;
case 'MBs':
$speedTypeOperator = "7812.5";
break;
}
}
$_SESSION['Time'] = ($data*$dataTypeOperator)/($speed*$speedTypeOperator);
/*TEST SESSION
echo 'Time=('.$data.' * '.$dataTypeOperator.') / ('.$speed.' * '.$speedTypeOperator.')<br>';
echo 'Time='.($time/60).'min';
echo '<br>dataTO: '.$dataTypeOperator.' speedTO: '.$speedTypeOperator;
die();
*/
header("Location: ../page.php?p=scripts&show=ETA&results=on");
? >
<button onclick="goBack()">Naspäť</button>
<script>function goBack() {window.history.go(-2);}</script>
[Editovať obrázok]
Popis: Kód, ktorý najprv umožní uploadovať na server obrázok, a následne ho upravovať, alebo zo servera vymazať. Tento kód nie je dokončený, pretože bol veľmi časovo náročný. Zatiaľ zvláda obrázok nahrať, premenovať, a vymazať (ale momentálne je v ňom aj nejaká iná chyba :P)
Kód:
scripts.php; časť "IMGedit"; formulár
<a id="show_id_2" onclick="document.getElementById('spoiler_id_2').style.display=''; document.getElementById('show_id_2').style.display='none';" class="link">
[Editovať obrázok]</a>
<span id="spoiler_id_2" style="display: none"><a onclick="document.getElementById('spoiler_id_2').style.display='none'; document.getElementById('show_id_2').style.display='';" class="link"><strike>[Editovať obrázok]</strike></a><br>
<?php
if (isset($_GET['show']) && $_GET['show'] == "IMGedit")
{
echo '<script>document.getElementById('spoiler_id_2').style.display=''; document.getElementById('show_id_2').style.display='none';</script>';
}
? >
<?php
/*if (!isset($_SESSION['fileWorking']))
{
$_SESSION['uploaded'] = '0';
echo "
<form name=\"IMGupload\" action=\"scripts/IMGedit.php\" method=\"post\" enctype=\"multipart/form-data\">
<br>
<table border=\"0\">
<tr>
<td>Obrázok: </td>
<td><input type=\"file\" name=\"IMGupload\"></td>
</tr>
<tr><td> </td><td> </td></tr><tr><td></td>
<td><input type=\"submit\" value=\"Nahrať súbor\"></td>
</tr>
</table>
</form>";
}
else
{
echo "
<form name=\"IMGedit\" action=\"scripts/IMGedit.php\" method=\"post\">
<br>
<hr>
Veľkosť a kvalita obrázka je pre ukážku redukovaná. Okraj je dočasný. <br><br>
<center><img src=\"scripts\".$_SESSION['fileWorking']."\" alt=\"\" border=\"5\" style=\"max-width: 500px;\"></center>
<hr>
<br>
<table border=\"0\">
<tr>
<td><center><b>Efekt</b></center></td>
<td><center><b>Hodnota</b></center></td>
</tr>
<tr style=\"border-bottom: 1px solid;\">
<tr>
<td>JAS</td>
<td>-255 <input type=\"range\" name=\"FX_1\" min=\"-255\" max=\"255\" step=\"1\"> 255</td>
</tr>
<tr>
<td>FX_NAME2</td>
<td>-255 <input type=\"range\" name=\"FX_2\" min=\"-255\" max=\"255\" step=\"1\"> 255</td>
</tr>
<tr>
<td><input type=\"submit\" name=\"sumbit\" value=\"Urobiť úpravy\"></td>
<td><input type=\"submit\" name=\"delete\" value=\"Vymazať obrázok\"></td>
</tr>
</table>
</form>";
}
*/
? >
<pre style="font-size: 12px">
Táto časť nefunguje len tu, kvôli limitáciám školského serveru
(upload_max_filesize / post_max_size v súbore php.ini)</pre>
</span><br>
scripts/IMGedit.php; skript
<?php
session_start();ss
//RANDOM string, 10 or custom
function RandomString($length = 10)
{
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$tmpString = '';
for ($i = 0; $i < $length; $i++)
{
$tmpString .= $characters[rand(0, $charactersLength - 1)];
}
return $tmpString;
}
//just DELETE ?
if (isset($_POST['delete']))
{
unlink($_SESSION['fileWorking']);
unset($_SESSION['fileWorking']);
unset($_SESSION['origFile']);
header('Location: ../page.php?p=scripts&show=IMGedit');
}
//UPLOADER;
if($_SESSION['uploaded'] == '0')
{
$_SESSION['uploaded'] = '1';
//UPLOAD
$targetDir = "IMGedit/";
$targetFile = $targetDir . basename($_FILES["IMGupload"]["name"]);
$uploadOk = 1;
$_SESSION['imageFileType'] = pathinfo($targetFile,PATHINFO_EXTENSION);
//CHECK img EXTENSION
if($_SESSION['imageFileType'] != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" )
{
$uploadOk = 0;
}
//MOVE and RENAME to TEMP
if ($uploadOk == 1)
{
$temp = explode(".",$_FILES["IMGupload"]["name"]);
$newFileName = RandomString(10) . '.' .end($temp);
move_uploaded_file ($_FILES["IMGupload"]["tmp_name"] , $targetDir . $newFileName);
$_SESSION['fileWorking'] = $targetDir . $newFileName;
$_SESSION['origFile'] = $targetFile;
header('Location: ../page.php?p=scripts&show=IMGedit');
}
else
{
//UNUSED (if==true)
print_r(get_defined_vars());
die();
header('Location: ../page.php?p=error&r=img');
}
switch ($_SESSION['imageFileType'])
{
case 'png':
$img = @imagecreatefrompng($_SESSION['fileWorking']);
break;
case 'jpg':
$img = @imagecreatefromjpeg($_SESSION['fileWorking']);
break;
case 'jpeg':
$img = @imagecreatefromjpeg($_SESSION['fileWorking']);
break;
}
$temp = explode(".",$_SESSION['fileWorking']);
$_SESSION['fileWorking'] = reset($temp) .'.jpg';
imagejpeg($img, $_SESSION['fileWorking']); //Save working IMG
}
else
{
//Picture is uploaded, saved in $_SESSION['img']; path $_SESSION['fileWorking']
//move FXs to arrays
$img = @imagecreatefromjpeg($_SESSION['fileWorking']);
$FX = array();
for($i=1; $i<=2; $i++) //i<=x; x=number of times
{
$FX[$i] = $_POST['FX_'.$i];
}
if(isset($FX['1']))
{
imagefilter($img, IMG_FILTER_BRIGHTNESS, $FX['1']);
}
if(isset($FX['2'])) imagefilter($img, IMG_FILTER_BRIGHTNESS, $FX['2']);
if(isset($FX['3'])) imagefilter($img, IMG_FILTER_BRIGHTNESS, $FX['3']);
echo $FX['1'];
echo $_SESSION['imageFileType'];
if(!isset($_SESSION['img'])) echo ' notset ';
echo $_SESSION['fileWorking'];
}
imagejpeg($_SESSION['img'], $_SESSION['fileWorking']);
//header('Location: ../page.php?p=scripts&show=IMGedit');
?>
<button onclick="goBack()">Naspäť</button>
<script>function goBack() {window.history.go(-1);}</script><br><br>
<button onclick="goForw()">Dalej</button>
<script>function goForw() {window.history.go(-1);}</script>
[Náhodný generátor]
Popis: Generátor, do ktorého zadáte dĺžku reťazca a znaky na generáciu, a vygeneruje reťazec vaších požiadavok. V prípade nezadania jednej alebo oboch vlastností, použijú sa prednastavené (v mojom prípade dĺžka 10 a znaky a-z;A-Z;0-9)
Kód:
scripts.php; časť "randg"; formulár
<a id="show_id_3" onclick="document.getElementById('spoiler_id_3').style.display=''; document.getElementById('show_id_3').style.display='none';" class="link">
[Náhodný generátor]</a>
<span id="spoiler_id_3" style="display: none"><a onclick="document.getElementById('spoiler_id_3').style.display='none'; document.getElementById('show_id_3').style.display='';" class="link"><strike>[Náhodný generátor]</strike></a><br>
<?php
if (isset($_GET['show']) && $_GET['show'] == "randg")
{
echo '<script>document.getElementById('spoiler_id_3').style.display=''; document.getElementById('show_id_3').style.display='none';</script>';
}
?>
<form name="randg" action="scripts/randg.php" method="post">
<table border="0">
<tr>
<td>Dĺžka reťazca</td>
<td><input type="text" name="length" size="10"> Ak je pole prázdne, použije sa "10"</td>
</tr>
<tr>
<td>Generované znaky</td>
<td><input type="text" name="buffer" size="10"> Ak je pole prázdne, použije sa "a-z;A-Z;0-9"</td>
</tr>
</table>
<input type="submit" value="Generovať">
</form>
<?php
if (!empty($_SESSION['randresult']))
{
echo "<hr><h4>Reťazec:</h4><span style=\"word-wrap: break-word;\">".$_SESSION['randresult']."</span><br><br>";
unset($_SESSION['randresult']);
}
?>
</span><br>
scripts/randg.php; skript
<?php
session_start();
$_SESSION['buffer'] = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$_SESSION['length'] = '10';
//Send data to Generator
if (empty($_POST['length']))
{
if (empty($_POST['buffer']))
{
$r = RandomString($_SESSION['length'], $_SESSION['buffer']);
}
else
{
$r = RandomString($_SESSION['length'], $_POST['buffer']);
}
}
else
{
if (empty($_POST['buffer']))
{
$r = RandomString($_POST['length'], $_SESSION['buffer']);
}
else
{
$r = RandomString($_POST['length'], $_POST['buffer']);
}
}
//Sender
$_SESSION['randresult'] = $r;
header('Location: ../page.php?p=scripts&show=randg');
//Generator
function RandomString($length, $chars)
{
$charactersLength = strlen($chars);
$tmpString = '';
for ($i = 0; $i < $length; $i++)
{
$tmpString .= $chars[rand(0, $charactersLength - 1)];
}
$tmpString .= "<br>#0: ".substr_count($tmpString, 0)."<br>#1: ".substr_count($tmpString, 1)."<br> %0: ".((substr_count($tmpString, 0) * 100) / (substr_count($tmpString, 0) + substr_count($tmpString, 1)));
return $tmpString;
}
?>