<meta http-equiv="Content-Type" content="text/html; charset=Windows-1251" />
<table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td><strong></strong></td>
</tr>
<tr>
<td>избор на файл
<input name="file_name" type="file" id="ufile" size="50" /></td>
</tr>
<tr>
<td align="center"><input type="submit" name="submit" value="Качи!" /></td></tr>
</table>
</td>
</form>
</tr>
</table>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<a href="index.php">Начало</a> <br /><br />
<?php
if (isset($_POST['submit']))
{
# Името на сайта, или линка :)
define(LOCATION,"http://localhost/");
$folder = "audio/";
$open_type_upload = ".mp3";
# Различните типове на файловете, които са ни нужни
$file_name = $_FILES['file_name']['name'];
$file_tmp = $_FILES['file_name']['tmp_name'];
$file_size = $_FILES['file_name']['tmp_size'];
$file_type = $_FILES['file_name']['type'];
# Избиране на происволно име на файла.
$rand_file_name = rand(1000000000, 9999999999999);
# Новото име на файла
$newfile_name = $rand_file_name.$file_name;
# Позволени типове файлове, които могат да се качват само.
$open_types = array(
"audio/mpeg",
);
if(!in_array($file_type, $open_types)) {
echo "Този формат файл не е позволен!";
}
else {
if (file_exists($folder.$rand_file_name.$open_type_upload)) {
echo "Този файл вече съществува. Моля опитайте отново!";
}
else {
$upload = move_uploaded_file($file_tmp, $folder.$rand_file_name.$open_type_upload);
if ($upload == true) {
echo "Всичко премина добре :d";
}
}
}
}
?>