Hi all, i need some help with my php code. I want to create upload form with 4 fields : two dropdown buttons, 1 text field and the browse button. I have problem with validating my files ,because i want only to upload pptx, ppt and pdf files , to check the file name , because it can be written in cyrillic and a don't want this. Also if there is the same file in the DB to change the name ( it' can be done with-- $random_digit=rand(0000,9999); $new_file_name=$random_digit.$file_name;-- or something like that) Can anyone help me, my code till now is :
<body>
<?php
if(isset($_POST['upload'])){
$class=$_POST['class'];
$subject=$_POST['subject'];
$lesson=$_POST['lesson'];
$target = "upload/";
$target = $target . basename( $_FILES['file']['name']) ;
$ok=1;
/*if($class=='0')
{ print ("Изберете клас");}
else{
if($subject=='0')
{ print("Избери предмет"); }
else{
if(empty($lesson))
{ print("Въведи име на урока");}
else{*/
$ext= pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
echo $ext."<br />";
/* echo $_FILES['file']['size']. " = razmer <br />";
echo $_FILES['file']['name']. " = ime <br />";
echo $_FILES['file']['type']. " = tip <br />";
echo $_FILES['file']['tmp_name']. " = temp <br />"; */
if($ext!='pptx' || $ext!="pdf" )
{$error= "Файлът е с грешно разширение.";
echo $error;}
else{
if ($_FILES['file']['size'] > 10500000)
{
echo "Файлът е прекалено голям.<br>";
$ok=0;
}
if ($ok==0)
{
Echo "Файлът не беше качен!";
}
else{
if(move_uploaded_file($_FILES['file']['tmp_name'], $target))
{
echo "Фаилът ". basename( $_FILES['file']['name']). " е прикачен успешно.<br /> <br />";
}
else {
echo "Възникнал е проблем с прикачването. Опитайте отново.";
}
}
}
}
/*
}
}
}
*/
?>
<div style="width:700px; height:500px;">
<div class="asking" id="upload" >
Прикачи урок<br /><br /><br />
<form name="uploadf" method="post" action="" enctype="multipart/form-data">
<table width="500px" cellpadding="0" cellspacing="0" border="1" id="form">
<tr>
<td ><span style="margin-right:10px;">Клас:</span><select name="class" type="list" size="1" id="class" style=" width:100px; font-size: 13px;">
<option value='0' selected='yes' ></option><option value='I клас' >I клас</option><option value='II клас' >II клас</option><option value='III клас' >III клас</option><option value='IV клас' >IV клас</option>
</select>
<span style="margin-left:40px; margin-right:10px;">Предмет: <select name="subject" type="list" size="1" id="class" style=" width:100px; font-size: 13px;">
<option value='0' selected='yes' ></option><option value='Български език' >Български език</option><option value='Математика' >Математика</option><option value='Роден край'>Роден край</option><option value='Домашен бит и техника'>Домашен бит и техника</option><option value='Околен свят'>Околен свят</option><option value='Човек и общество'>Човек и общество</option><option value='Човек и природа'>Човек и природа</option>
</select>
</td>
</tr>
<tr>
<td ><span style="margin-right:10px;">Име на урок:</span> <input type="text" name="lesson" style="font-size: 13px;">
</tr>
<tr>
<td ><span style="margin-right:10px;">Избери файл:</span><input type="file" name="file" style="width:230px; height:25px; padding:3px; position:relative;" /></td>
</tr>
<tr>
<td align="right"><input type="submit" name="upload" value="Прикачи" class="button" id="submit"/></td>
</tr>
</table>
</form>
</div>
</div>
</body>
thanks in advance :)