视频无法通过php上传

时间:2016-01-10 02:02:01

标签: php mysql upload

首先,这是我的代码,来自第一页,表单,页面:

    <form method="POST" action="uploadMovieProcess.php" enctype="multipart/form-data">



    <br><br>
    <label for="movieTitle" class="thicker4">Movie Title: </label><input type="text" 
    id="movieTitle" name="movieTitle" size="50" placeholder="E.g. Hobbit An Unexpected Journey, The"/>

    <br><br>
    <label for="movieUrl" class="thicker4">Movie File Name: </label><input type="text" 
    id="movieUrl" name="movieUrl" size="50" onkeyup="nospaces(this)" placeholder="E.g. hobbitAnUnexpectedJourney,The.mp4"/>


    <br><br><text class="thicker4">Upload Movie Here: </text>
 <input type="file" name="movieUrl" id="movieUrl">
 <value="movieUrl" name="submit">
    <p class="thicker3">Or drag and drop on top of the choose file button</p>

     <input type="submit">
    </form>

这是来自第二个流程页面的代码:

    // this handles the video

    $target_dir = "movies/";
    $target_file = $target_dir . basename($_FILES["movieUrl"]["name"]);
    $uploadOk = 1;
    $videoFileType = pathinfo($target_file,PATHINFO_EXTENSION);

    // Check if file already exists
    if (file_exists($target_file)) {
    echo "This film is already on this database, or atleast there's a file with the same name...";
$uploadOk = 0;
    }

     // Allow certain file formats
     if($videoFileType != "mp4" && $videoFileType != "ogg" && $videoFileType != "eog"
    && $videoFileType != "webm" ) {
   echo "Sorry, only MP4, Ogg, Eog & WebM formats are allowed.";
$uploadOk = 0;
     }



     // this handles the database

     $movieTitle=$_POST["movieTitle"];   
    $movieUrl=$_POST["movieUrl"]; 

    $mysqlserver="localhost"; 
    $mysqlusername="jakedean";
    $mysqlpassword="jakedean";
    $link=mysql_connect($mysqlserver, $mysqlusername, $mysqlpassword) or die    ("Error connecting to mysql server: ".mysql_error());

    $dbname = 'allMovies';
     mysql_select_db($dbname, $link) or die ("Error selecting specified         database on mysql server: ".mysql_error());
        // the query which inserts the new data (from the variables) is set up and run

     $addMoviequery="INSERT INTO movies 
(movieTitle, movieUrl)
VALUES 
('$movieTitle', 'movies/$movieUrl')";
    mysql_query($addMoviequery) or die("Query to insert new movie into movies failed with this error: ".mysql_error());            

echo "<button class=\"buttonStyle\" onclick=\"location.href='index.php'\">Or, Click here</button>";

    echo "<p class=\"thicker2\">You Added a new movie! The information of   this movie is:</p>
            <p class=\"bold\">Movie Title:</p> <p class=\"thicker\">$movieTitle</p> 
    <p class=\"bold\">Movie File Name:</p> <p class=\"thicker\">$movieUrl</p>"
    ?>

在我的控制台中我没有收到错误,变量被插入数据库绝对没问题,只是上传的视频没有到达目录。

点击提交后,网页上传(1%)并达到100%,然后重定向到流程页面......但视频不在第二页第一行代码的目录中,如果是上传,它会在哪里?

我已经检查了我的php.ini文件,一切都已启用且限制正确。我想不出别的什么。

这让我困惑了好几个小时,提前致谢

2 个答案:

答案 0 :(得分:0)

潜在地,它不是你的脚本问题。 服务器安装的上传限制是多少......默认值是2MB。

检查php.ini文件中的upload_max_filesize和post_max_size值。

客户端看起来好像正在上传文件,但上传会失败。

答案 1 :(得分:0)

尝试从

更改
 $movieTitle=$_POST["movieTitle"];   
 $movieUrl=$_POST["movieUrl"]; 

 $movieTitle=$_FILES["movieTitle"];   
  $movieUrl=$_FILES["movieUrl"];