jози код ми дава странна греика

Pro_Lamer4e

Registered
като се опитам да кача някой файл и ми пише Файлът е повреден

Код:
<?php
if(isset($_POST['submit'])){
include "../connect.php";
$id = (int)$_GET['id'];
$ip = $_SERVER['REMOTE_ADDR'];
$direct = $_POST['direct'];
$file=$_FILES['file']['name'];
$tmp_file=$_FILES['file']['tmp_name'];
$size=$_FILES['file']['size'];
$upload_path="".$direct."".basename($file);
if(empty($file)) {
echo "Моля изберете файл";
echo '</td>
<td class="c_right"><img src="../images/blank.gif" width="2" height="2" alt="" border="0"></td>
</tr>
<tr>
<td class="d_left"><img src="../images/blank.gif" width="1" height="1" alt="" border="0"></td>
<td class="d_center"><img src="../images/blank.gif" width="1" height="1" alt="" border="0"></td>
<td class="d_right"><img src="../images/blank.gif" width="1" height="1" alt="" border="0"></td>
</tr>
</table>';
require("style2.php");
exit;
}

if(file_exists($upload_path)){
echo "Файлът вече съществува";
echo '</td>
<td class="c_right"><img src="../images/blank.gif" width="2" height="2" alt="" border="0"></td>
</tr>
<tr>
<td class="d_left"><img src="../images/blank.gif" width="1" height="1" alt="" border="0"></td>
<td class="d_center"><img src="../images/blank.gif" width="1" height="1" alt="" border="0"></td>
<td class="d_right"><img src="../images/blank.gif" width="1" height="1" alt="" border="0"></td>
</tr>
</table>';
require("style2.php");
exit;
}

if($size==0){
echo "Файлът е повреден";
echo '</td>
<td class="c_right"><img src="../images/blank.gif" width="2" height="2" alt="" border="0"></td>
</tr>
<tr>
<td class="d_left"><img src="../images/blank.gif" width="1" height="1" alt="" border="0"></td>
<td class="d_center"><img src="../images/blank.gif" width="1" height="1" alt="" border="0"></td>
<td class="d_right"><img src="../images/blank.gif" width="1" height="1" alt="" border="0"></td>
</tr>
</table>';
require("style2.php");
exit;
}

 function random_string($max = 20){
  $chars = explode(" ", 'a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9');
  for($i = 0; $i < $max; $i++){
   $rand_key = array_rand($chars);
   $screen1  .= $chars[$rand_key];
  }
  return str_shuffle($screen1);
 }

if($size>5242880){
echo "Файлът е твърде голям";
echo '</td>
<td class="c_right"><img src="../images/blank.gif" width="2" height="2" alt="" border="0"></td>
</tr>
<tr>
<td class="d_left"><img src="../images/blank.gif" width="1" height="1" alt="" border="0"></td>
<td class="d_center"><img src="../images/blank.gif" width="1" height="1" alt="" border="0"></td>
<td class="d_right"><img src="../images/blank.gif" width="1" height="1" alt="" border="0"></td>
</tr>
</table>';
require("style2.php");
exit;
}

$extensions = array("rar","zip","html","jpg","jpeg","gif","png","bmp","js","txt","css");
$extension_file = end(explode(".",$file));
$extension_file = strtolower($extension_file);
if(!in_array($extension_file,$extensions)){
echo "Непозволен тип файл";
echo '</td>
<td class="c_right"><img src="../images/blank.gif" width="2" height="2" alt="" border="0"></td>
</tr>
<tr>
<td class="d_left"><img src="../images/blank.gif" width="1" height="1" alt="" border="0"></td>
<td class="d_center"><img src="../images/blank.gif" width="1" height="1" alt="" border="0"></td>
<td class="d_right"><img src="../images/blank.gif" width="1" height="1" alt="" border="0"></td>
</tr>
</table>';
require("style2.php");
exit;
}

$upload=move_uploaded_file($tmp_file,$upload_path);
if($upload){
$q=mysql_query("INSERT INTO `filesystem` (`id`,`file`,`direct`,`ip`,`size`) VALUES ('$id','$file','$direct','$ip','$size')");
if($q = TRUE){
echo "<font color=\"green\">Файлът беше успешно качен</font>";
}else{
echo "<font color=\"red\">Грешка</font></center>";
exit;
}
}
}else{
?>
<form action="" method="post" enctype = "multipart/form-data">
<table width="95%" border="0">
<tr><td>Файл:</td><td><input name="file" type="file">
<br><font color="green">Изберете файл, който да качите.</font></td></tr>
<tr><td></td><td><hr></td></tr>
<tr><td>Директория:</td><td><select name="direct">
<option value="../">начална</option>
<option value="./codes/">codes</option>
<option value="../images/">images</option>
<option value="../wsys_functions/">wsys_functions</option>
</select>
<br><font color="green">Изберете къде да качите файла.</font></td></tr>
<tr><td></td><td><hr></td></tr>
<tr><td></td><td><input name="submit" type="submit" value="Давай!"></td></tr>
</table>
</form>
<?php
}
?>

ето и sql-a
Код:
CREATE TABLE `filesystem` (
`id` int( 12 ) NOT NULL AUTO_INCREMENT ,
`file` varchar( 255 ) NOT NULL ,
`direct` varchar( 255 ) NOT NULL ,
`ip` varchar( 255 ) NOT NULL ,
`size` varchar( 255 ) NOT NULL ,
PRIMARY KEY ( `id` )
) ENGINE = MYISAM DEFAULT CHARSET cp1251 COLLATE cp1251_bulgarian_ci AUTO_INCREMENT =1;
 
Пробвай така!

Код:
<?php
if(isset($_POST['submit'])){
include "../connect.php";
$id = (int)$_GET['id'];
$ip = $_SERVER['REMOTE_ADDR'];
$direct = $_POST['direct'];
$file=$_FILES['file']['name'];
$tmp_file=$_FILES['file']['tmp_name'];
$size=$_FILES['file']['size'];
$upload_path="".$direct."".basename($file);
if(empty($file)) {
echo "Моля изберете файл";
echo '</td>
<td class="c_right"><img src="../images/blank.gif" width="2" height="2" alt="" border="0"></td>
</tr>
<tr>
<td class="d_left"><img src="../images/blank.gif" width="1" height="1" alt="" border="0"></td>
<td class="d_center"><img src="../images/blank.gif" width="1" height="1" alt="" border="0"></td>
<td class="d_right"><img src="../images/blank.gif" width="1" height="1" alt="" border="0"></td>
</tr>
</table>';
require("style2.php");
exit;
}

if(file_exists($upload_path)){
echo "Файлът вече съществува";
echo '</td>
<td class="c_right"><img src="../images/blank.gif" width="2" height="2" alt="" border="0"></td>
</tr>
<tr>
<td class="d_left"><img src="../images/blank.gif" width="1" height="1" alt="" border="0"></td>
<td class="d_center"><img src="../images/blank.gif" width="1" height="1" alt="" border="0"></td>
<td class="d_right"><img src="../images/blank.gif" width="1" height="1" alt="" border="0"></td>
</tr>
</table>';
require("style2.php");
exit;
}

if($size=="0"){
echo "Файлът е повреден";
echo '</td>
<td class="c_right"><img src="../images/blank.gif" width="2" height="2" alt="" border="0"></td>
</tr>
<tr>
<td class="d_left"><img src="../images/blank.gif" width="1" height="1" alt="" border="0"></td>
<td class="d_center"><img src="../images/blank.gif" width="1" height="1" alt="" border="0"></td>
<td class="d_right"><img src="../images/blank.gif" width="1" height="1" alt="" border="0"></td>
</tr>
</table>';
require("style2.php");
exit;
}

 function random_string($max = 20){
  $chars = explode(" ", 'a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9');
  for($i = 0; $i < $max; $i++){
   $rand_key = array_rand($chars);
   $screen1  .= $chars[$rand_key];
  }
  return str_shuffle($screen1);
 }

if($size>5242880){
echo "Файлът е твърде голям";
echo '</td>
<td class="c_right"><img src="../images/blank.gif" width="2" height="2" alt="" border="0"></td>
</tr>
<tr>
<td class="d_left"><img src="../images/blank.gif" width="1" height="1" alt="" border="0"></td>
<td class="d_center"><img src="../images/blank.gif" width="1" height="1" alt="" border="0"></td>
<td class="d_right"><img src="../images/blank.gif" width="1" height="1" alt="" border="0"></td>
</tr>
</table>';
require("style2.php");
exit;
}

$extensions = array("rar","zip","html","jpg","jpeg","gif","png","bmp","js","txt","css");
$extension_file = end(explode(".",$file));
$extension_file = strtolower($extension_file);
if(!in_array($extension_file,$extensions)){
echo "Непозволен тип файл";
echo '</td>
<td class="c_right"><img src="../images/blank.gif" width="2" height="2" alt="" border="0"></td>
</tr>
<tr>
<td class="d_left"><img src="../images/blank.gif" width="1" height="1" alt="" border="0"></td>
<td class="d_center"><img src="../images/blank.gif" width="1" height="1" alt="" border="0"></td>
<td class="d_right"><img src="../images/blank.gif" width="1" height="1" alt="" border="0"></td>
</tr>
</table>';
require("style2.php");
exit;
}

$upload=move_uploaded_file($tmp_file,$upload_path);
if($upload){
$q=mysql_query("INSERT INTO `filesystem` (`id`,`file`,`direct`,`ip`,`size`) VALUES ('$id','$file','$direct','$ip','$size')");
if($q = TRUE){
echo "<font color=\"green\">Файлът беше успешно качен</font>";
}else{
echo "<font color=\"red\">Грешка</font></center>";
exit;
}
}
}else{
?>
<form action="" method="post" enctype = "multipart/form-data">
<table width="95%" border="0">
<tr><td>Файл:</td><td><input name="file" type="file">
<br><font color="green">Изберете файл, който да качите.</font></td></tr>
<tr><td></td><td><hr></td></tr>
<tr><td>Директория:</td><td><select name="direct">
<option value="../">начална</option>
<option value="./codes/">codes</option>
<option value="../images/">images</option>
<option value="../wsys_functions/">wsys_functions</option>
</select>
<br><font color="green">Изберете къде да качите файла.</font></td></tr>
<tr><td></td><td><hr></td></tr>
<tr><td></td><td><input name="submit" type="submit" value="Давай!"></td></tr>
</table>
</form>
<?php
}
?>
 

Back
Горе