视频上传脚本不起作用

时间:2011-02-24 06:24:02

标签: php mysql video upload

这是新手,但我已经摸不着头脑了。 Vids没有上传/正在创建,但没有错误消息,文件名/目录位置也被记录到MySQL中。

HUH?!

以下是代码:


<?php

date_default_timezone_set("America/New_York");
include("functionpage.php");
session_start();

if (isset($_SESSION['firstname']))
{

if (isset($_POST["submit"]) && $_FILES["uploadfile"]["name"] != "")
{                                                               


  if (!$connect = mysqli_connect($lh, $rt, $pw, $gj))
  {     
        echo "<p>We're sorry, but the connection to the server is currently unavailable. <br />  Thank you for your patience.<br /><br />
        exit();
  }

  $namefirst = $_SESSION['firstname'];

  echo $namefirst."<br /><br />";

  $sql = "SELECT * FROM cust_vids WHERE firstname = '$namefirst'";

  $result = mysqli_query($connect,$sql);

  if (mysqli_num_rows($result) > 0)
  {
          $rows = mysqli_fetch_assoc($result);
          extract($rows);

          $directory = "videos/".$username."/".$namefirst;

          if(!is_dir($directory))
          {
                  mkdir($directory);
          }

          $uploadfile = mysqli_real_escape_string($connect,$_FILES["uploadfile"]["name"]);
          $uploadfile = strtolower(trim($uploadfile));
          $vidtype = $_FILES["uploadfile"]["type"];
          $vidsize = $_FILES["uploadfile"]["size"] / 1024;
          $vidtmp = $_FILES["uploadfile"]["tmp_name"];
          include("layout.php");
          echo "Upload: " . $uploadfile . "<br />";
          echo "Type: " . $vidtype . "<br />";
          echo "Size: " . $vidsize . " Kb<br />";
          echo "Stored in: " . $vidtmp."<br /><br />";
          echo $username."<br />";
          echo $firstname."<br />";
          echo $namefirst."<br />";

          $extension = explode(".",$uploadfile);
          $ext = $extension[1];
          $permloc = $directory.$uploadfile;

          echo "<p>".$ext."<br />";

          /*Will check to see if the file has an extension that isn't allowed*/
          if ($ext != "swf" && $ext != "mov" && $ext != "wmv" && $ext != "avi" && $ext != "mpg" && $ext != "mpeg"
                && $ext != "mp4" && $ext != "flv")
          {
                echo "<p>We're sorry, but we do not support this type of file. <br />
                Thank you for your patience.<br /><br />
                <a href=\"uploadvid.php\">Back to upload video form</a><br />
                exit();
          }


          if (file_exists($permloc))
          {
                  echo "<p>File already exists.<br /><br />
                  <a href=\"blog.php\">Back to Main Blog Page</a>.</p>";
                  exit();
          }
          else
          {
                  move_uploaded_file($vidtmp,$permloc);
                  echo "<br />New location: ".$permloc."<br /><br />";
                  $sql2 = "INSERT INTO cust_vids (username, firstname, uploadvids,videolocation) 
                  VALUES (\"$username\",\"$firstname\", \"$uploadfile\", \"$permloc\")";

                  $result2 = mysqli_query($connect,$sql2);
                  if (!$result2)
                  {
                        echo "<p>Sorry, but your file was not uploaded into our records. Please try again.<br /><br />
                        <a href=\"uploadvid.php\">Back to upload video form</a><br />
                        <a href=\"blog.php\">Back to Main Blog Page</a>.</p>";
                        exit();
                  }
                  else
                  {
                        echo "<p>The file has been uploaded into your account successfully.<br /><br />
                        Back to <a href=\"Blog.php\">Main Blog Page</a></p>";
                        exit();
                  }   
          }
  }
  else
  {
      include("layout.php");
      echo "<p>We're sorry, but there is no user account under that username. Please try again. <br /><br />
      <a href=\"uploadvid.php\">Back to upload video form</a><br />
      <a href=\"blog.php\">Back to Main Blog Page</a>.</p>";
      exit();
  }
}
}
else
{
    header("location:blog.php");
}

?>



<html>
<head>
<title>Test script</title>
</head>

<body>
    <?php include("layout.php"); ?>

    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data">
    <input type="hidden" name="MAXFILESIZE" value="2147483648" /><!--Equals to around 28 mb-->
    ADD SCENE:
    <input type="file" name='uploadfile' size="30" maxlength="100"/><br />
    <input type= "submit" name="submit" value="UPLOAD"/>
    </form>
</body>
</html>

/ 文件结尾 /


任何帮助/见解将不胜感激。 THX!

2 个答案:

答案 0 :(得分:1)

您的服务器可能有一个服务器的size_limit,您也必须将其设置为php上传脚本的设置。

答案 1 :(得分:0)

检查“file_uploads”是否设置为“On”,“upload_max_filesize”是否足够。