【发布时间】:2016-01-10 02:02:00
【问题描述】:
首先,这是我的第一个表单页面的代码:
<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 文件,一切都已启用并且限制是正确的。我想不出别的了。
这让我困惑了好几个小时,在此先感谢
【问题讨论】:
-
php.net/manual/en/function.move-uploaded-file.php 到
/movies/filename -
我测试过这个; move_uploaded_file($target_file , $target_dir);在处理数据库的代码之前,我没有错误但视频不在目录中,我不知道它在哪里!