-2

i need your help, im trying to upload video files to server, below are videoadmininsert.php, this file is what the user see, and videosave.php, is where the verification for the file are made , then save the file on a folder in the server. the problem is when a choose a video file,for example the one i'm trying to upload got 25mb and the format is wmv, the server say that the file choosen was not the correct file extension. videoadmin.php

<?php
session_start();
$host="localhost"; // Host name
$username="ccili_userccili"; // Mysql username
$password="xxxxxxxxxxxxxxxx"; // Mysql password
$db_7name="ccili_BD"; // Database name
$tbl_name="Video"; // Table name


// Connect to server and select databse.
$con=  mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

mysql_query("SET NAMES 'utf8'");
$_SESSION['whattodo']="insert";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org    /TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
   <title>Camara do comercio e industria Portugal - Iraque</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
   <link rel="stylesheet" type="text/css" href="StyleSheet.css" />

</head>
<body onload="display_ct(),display_ct2();">

<div id="wrap">
<div id="header">
 <div id="Div1">
<div class="row dropdown-container fixed">
<div class="col-220">
<a id="logo" title="Back to amin" href="login_sucess.php">
<img width="220" alt="logo" src="../Images/logo.jpg"/>
</a>
</div>
<div class="col-701 last">
<p>&nbsp;</p>
<p class="get-in-touch">
<img width="14" height="10" alt="" src="../Images/flagpt.jpg"/>
<strong>
<script type="text/javascript">
    function display_c() {
    var refresh = 1000; // Refresh rate in milli seconds
    mytime = setTimeout('display_ct()', refresh)
}

function display_ct() {
    var strcount
    var x = new Date()
    var horas = x.getHours();
    var min = x.getMinutes();
    var sec = x.getSeconds();
    if (horas < 10) {
        horas = "0" + horas;
    }
    if (min < 10) {
        min = "0" + min;
    }
    if (sec < 10) {
        sec = "0" + sec;
    }

    document.getElementById('ct').innerHTML = horas + ":" + min + ":" + sec + " ";
    tt = display_c();
}

      </script> <span id='ct' ></span>
</strong>
<img width="14" height="10" alt="" src="../Images/flagiraque.jpg"/>
<strong>
<script type="text/javascript">
function display_c2() {
    var refresh = 1000; // Refresh rate in milli seconds
    mytime2 = setTimeout('display_ct2()', refresh)
}

function display_ct2() {
    var strcount
    var x = new Date()
    var horas1 = x.getHours() + 2;
    var min1 = x.getMinutes();
    var sec1 = x.getSeconds();

    if (horas1 < 10) {
        horas1 = "0" + horas1;
    }
    if (horas1 > 24) {
        horas1 = "0" + (horas1 - 24);
    }

    if (min1 < 10) {
        min1 = "0" + min1;
    }
    if (sec1 < 10) {
        sec1 = "0" + sec1;
    }
    document.getElementById('ct2').innerHTML = horas1 + ":" + min1 + ":" + sec1 + " ";
    tt1 = display_c2();
}



</script> <span id='ct2' ></span>
</strong>
</p>
<p class="text-right">غرفة التجارة و الصناعة البرتغالية العراقية</p>
<p class="text-right1">Câmara do Comércio e Indústria Portugal-Iraque</p>
<p class="text-right">ژووری بازرگانی عیراق پۆرتگال</p>

</div>
</div>
</div>
</div>

<div id="content">
<div class="hr">
<p class="text-rightLogout"><a href="logout.php">Log Out!!!</a></p>
 </div> 
<div class="row fixed">
<div class="col-220">
<ul id="news-box">
<FORM name="form1" method="post" action="checkbutton.php">
<p><b>Home</b>
<INPUT TYPE="submit"  name ="Button1" ID="Button1" VALUE="Edit Home."  style="width:200px; height:30px;">
<INPUT TYPE="submit"  name ="Button2" ID="Button2" VALUE="Edit Culture PT" style="width:200px; height:30px;">
<INPUT TYPE="submit"  name ="Button3" ID="Button3" VALUE="Edit Culture IRAK" style="width:200px; height:30px;">
<b>About Us</b>
<INPUT TYPE="submit" name="Button4" ID="Button4" VALUE="Edit Mensagem Presidente"  style="width:200px; height:30px;">
<INPUT TYPE="submit"  name ="Button5" ID="Button5" VALUE="Edit Administration Board"  style="width:200px; height:30px;">
<INPUT TYPE="submit"  name ="Button6" ID="Button6" VALUE="Edit Consultive Board" style="width:200px; height:30px;">
<INPUT TYPE="submit"  name ="Button7" ID="Button7" VALUE="Edit General Assembly"  style="width:200px; height:30px;">
<INPUT TYPE="submit"  name ="Button8" ID="Button8" VALUE="Edit Financial Council"  style="width:200px; height:30px;">
<INPUT TYPE="submit"  name ="Button9" ID="Button9" VALUE="Edit Founding Members"  style="width:200px; height:30px;">
<b>Protocols</b>
<INPUT TYPE="submit"  name="Button10"ID="Button10" VALUE="Edit Protocols"     style="width:200px; height:30px;">
<b>Links</b>
<INPUT TYPE="submit"  name="Button11" ID="Button11" VALUE="Edit Links" style="width:200px;height:30px;">
<b>Photos/News/Videos</b>
<INPUT TYPE="submit"  name="Button12"ID="Button12" VALUE="Edit News" style="width:200px; height:30px;">
<INPUT TYPE="submit"  name="Button13"ID="Button13" VALUE="Edit Photos" style="width:200px;height:30px;">
<INPUT TYPE="submit"  name="Button14"ID="Button14" VALUE="Edit Videos" style="width:200px;height:30px;">
<b>Associates</b>
<INPUT TYPE="submit"  name="Button15"ID="Button15" VALUE="Edit How To Join" style="width:200px;height:30px;">
<INPUT TYPE="submit"  name="Button16"ID="Button16" VALUE="Edit List of Members" style="width:200px;height:30px;">
<INPUT TYPE="submit"  name="Button17"ID="Button17" VALUE="Edit Associates Prime" style="width:200px;height:30px;">
<b>Contacts</b>
<INPUT TYPE="submit"  name="Button18"ID="Button18" VALUE="Edit Adress" style="width:200px;height:30px;">
</FORM>
</p>
</ul>
</div>
<div class="col-460">
<?php
        echo "<center><h1>Videos</h1></Center>";
echo "<center><h1>Insert</h1></Center>";





 ?>

<form action="VideosAdminSave.php" method="post"
enctype="multipart/form-data">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Insert Video</strong></td>
</tr>
<tr>
<td width="78">Title</td>
<td width="6">:</td>
<td width="294"><input name="title" type="text" id="title"></td>
</tr>
<tr>
<td width="78">Text</td>
<td width="6">:</td>
<td width="294">
<?php
echo "<input type='textarea' name='text1'  size='61'> </textarea>" ;

?>
</td>
</tr>
<tr>
<td>File</td>
<td><label for="file">Filename:</label></td>
<td><input type="file" name="file" id="file" /></td>
</tr>
<tr>
<td><input type="submit" name="submitVideos" value="Submit" /></td>
</tr>
<input name="MAX_FILE_SIZE" value="40971520" type="hidden">

</table>
</td>
</form>



  </div>
</div>
<div id="footer">
<div class="row fixed">
<div class="col-220">
    <p >

        <img width="130" height="70"   alt="emb" src="Images/smartcom.jpg"/><br>
<strong>
&copy; 2012
<a href="http://www.smartcom.pt">Smartcom,
        <br/></a>Intelligent Communications&nbsp;


</strong>
</p>
<p >
All rights reserved.
<br/>

</p>
</div>
<div class="col-460 ">

</div>
</div>
</div>
</div>
</div>  

</body>
</html>

And here goes the videosadminsave

<?php

session_start();
$host="localhost"; // Host name
$username="ccili_userccili"; // Mysql username
$password='xxxxxxxxxxxx'; // Mysql password
$db_name="ccili_BD"; // Database name
$tbl_name="Video"; // Table name


// Connect to server and select databse.
$con=  mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

if(isset($_POST['Videos']))
{

 $delete=$_POST['Videos'];
 mysql_query("DELETE FROM Videos WHERE titulo='$delete' ");
 echo "<script type='text/javascript'> 

  window.location = ('VideosAdmin.php');
</script>";
  }
   $title=$_POST['title'];
//echo $namept;
$texto=$_POST['text'];

 $path="Videos/";

 $allowedExts = array("avi", "mp4", "flv","mpeg","3ggp","wmv");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "video/mp4")
|| ($_FILES["file"]["type"] == "video/avi")
|| ($_FILES["file"]["type"] == "video/flv")
|| ($_FILES["file"]["type"] == "video/mpeg")
|| ($_FILES["file"]["type"] == "video/wmv")
|| ($_FILES["file"]["type"] == "video/3ggp"))
&& ($_FILES["file"]["size"] < 100000000000000000000000000000000)
&& in_array($extension, $allowedExts))
  {
  if ($_FILES["file"]["error"] > 0)
{
 //echo "<script type='text/javascript'>
 //alert("Return Code: " . $_FILES["file"]["error"] . "<br />");
 //</script>"; 
//echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
 echo "<script type='text/javascript'> alert('Invalid File');window.location = ('VideosAdminInsert.php'); </script>";
  }
else
{
//echo "Upload: " . $_FILES["file"]["name"] . "<br />";
//echo "Type: " . $_FILES["file"]["type"] . "<br />";
//echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
//echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

if (file_exists($path . $_FILES["file"]["name"]))
  {

  //echo $_FILES["file"]["name"] . " already exists. ";
  //header("Location: editmsghome.php");
  echo "<script type='text/javascript'> alert('The file already exist, please change the file name.');window.location = ('VideosAdminInsert.php');
</script>"; 

  }
else
  {
  move_uploaded_file($_FILES["file"]["tmp_name"],
  $path . $_FILES["file"]["name"]);
        //header("Location: editmsghome.php");
//guardar na base de dados....
error_reporting(E_ALL);
ini_set('display_errors',1);
//ob_start();
//session_start();
if(isset($_FILES["file"]["name"]))
{
$video=$_FILES["file"]["name"];
}
else
{
$video="";
}

mysql_query("INSERT INTO Video ( titulo,ficheiro) VALUES ('$title','$video')");


mysql_close($con);
//session_destroy();

echo "<script type='text/javascript'> 
  alert('The video was stored in the server '); 
  window.location = ('VideosAdmin.php');
 </script>";

  //fim de guardar na base de dados...

     }
  }

  }  
  else
  {
  echo "<script type='text/javascript'> alert('Didnt choose the correct file... ');window.location = ('VideosAdmin.php'); </script>";
    }




?> 
4

1 回答 1

1

已编辑 - 在 OP 澄清后。

您的错误处理说“出现任何问题,显示相同的消息”这不会帮助您调试。

最可能的问题是 $_FILES 为空。您不检查“isset($_FILES['file'])”。要调试,只需 print_r($_FILES); 看看你得到了什么。一些更严重的文件上传错误会导致 $_FILES 为空,其他错误会出现在 $_FILES[name]['error'] 中。

还要检查大小 - 使用合理的限制,因为大数字处理可能会令人困惑(除非您将其转换为浮点数,否则请坚持使用整数进行有效比较,最大整数是 20 亿或 9.3e16)。

您的错误检查应该是:

  1. isset($_FILES['file'])
  2. $_FILES['文件']['错误']
  3. is_uploaded_file(以防万一您在共享服务器上)
  4. 其他标准(名称、大小等)

对于每一个,给出一个有意义的错误信息——这有助于准确地分解问题所在。

于 2012-08-22T03:55:44.360 回答