Cod: Selectaţi tot
<?php
//Creaza codul pentru fisiere
function createRandomPassword() {
$chars = "31287598174837129087498519785617361287618372198749150937382981651876";
srand((double)microtime()*1000000);
$i = 0;
$pass = '' ;
while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($chars, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}
// Usage
$cod_fisier = createRandomPassword();
//Stop cod pentru fisiere
// 1. Creati intai directorul cu numele 'upload' (in acelasi director cu pagina dv. de upload) in care se vor copia fisierele
// 2. Acordati directorului 'upload' permisiuni CHMOD 0777
// 3. introduceti tot acest cod intr-un fisier .php
$conn = mysql_connect("$host", "$user", "$parola")
or die("Unable to connect to MySQL");
$selectdb = mysql_select_db(''.$db.'');
// Preia datele din formular
$fisier=''. $_FILES['fisiere']['name']. '';
$sters="0";
$descarcari="0";
$data=$_POST['data'];
$ora=$_POST['ora'];
$ip=$_POST['ip'];
// Adauga datele in mySQL
$sql = "INSERT INTO `fisiere` (fisier, cod_fisier, descarcari, data, ora, sters, ip)
VALUES ('$fisier', '$cod_fisier', '$descarcari', '$data', '$ora', '$sters', '$ip.')";
// Se executa interogarea, daca returneaza FALSE afisaza cauza erorii, altfel, afiseaza confirmarea
if (!mysql_query($sql)) {
echo 'Eroare : '. mysql_errno(). ' - '. mysql_error();
}
else {
echo ' ';
}
$uploadpath = "files/";
// Aici este setata marimea maxima, in KiloBytes, care este permisa (dar marime maxima depinde si de setarile serverului)
$max_size = ''.$marime_fisiere.'';
// Aici puteti schimba tipul, extensia fisierelor permise pt. upload
$allowtype = array('bmp', 'flv', 'gif', 'jpg', 'jpeg', 'mp3', 'pdf', 'png', 'rar', 'zip', 'torrent');
if(isset($_POST['submit'])) {
if (isset ($_FILES['fisiere'])) {
$uploadpath = $uploadpath . basename( $_FILES['fisiere']['name']);
$type = end(explode(".", strtolower($_FILES['fisiere']['name'])));
// Daca fisierul are extensia permisa
if (in_array($type, $allowtype)) {
// Verifica daca fisierul are marimea permisa
if ($_FILES['fisiere']['size']<=$max_size*1000) {
if(move_uploaded_file($_FILES['fisiere']['tmp_name'], $uploadpath)) {
add_ip($_FILES['fisiere']['name']); // Apeleaza functia add_ip()
echo ''. $_FILES['fisiere']['name']. ' <font color="green"> OK '. $_FILES['fisiere']['size'] .' Bytes';
echo 'Download link :<br> <input type="text" name="thetext" size="60" value="'.$site.'/download.php?k='.$cod_fisier.'"> <br>Delete link:<br> <input type="text" name="thetext" size="60" value="'.$site.'/delete.php?k='.$cod_fisier.'">';
}
else {
echo "<b>Error from the services !";
}
}
else { echo 'Your file <b>'. $_FILES['fisiere']['name']. '</b> is very high. Max size: <i><b>'. $max_size. 'KB</b></i>'; }
}
else { echo 'Please change the extension.'; }
}
}
?>