嘿傢伙我是PHP語言的新手。我有一個大學項目,我必須創建虛擬教室,教師可以上傳視頻講座,學生可以訪問它。我堅持上傳和從MySQL數據庫檢索視頻的問題。我嘗試將視頻路徑保存到數據庫中,並將視頻保存到一個文件夾中,然後嘗試訪問它。但真正的問題是有時視頻正在上傳,有時候並非如此。每當我試圖保存視頻超過100 MB,路徑不能保存在數據庫中。但如果視頻尺寸較小,那麼它很容易保存到數據庫(我的意思是路徑)。我真的不明白問題是什麼,因爲我試圖保存路徑而不是視頻。任何人都可以幫忙嗎?使用php上傳和檢索mysql數據庫中的視頻
*********** THSI是我上傳的SCRIPT ***********
<?php
session_start();
require("/Applications/MAMP/htdocs/conn.php");
function is_valid_type($file)
{
$valid_types = array('video/mp4', 'video/mpeg', 'video/mpg', 'audio/mpeg');
if (in_array($file['type'], $valid_types))
return 1;
return 0;
}
function showContents($array)
{
echo "<pre>";
print_r($array);
echo "</pre>";
}
$TARGET_PATH = "/Applications/MAMP/htdocs/home/";
$id = $_POST['id'];
$name = $_POST['name'];
$video_path = $_FILES['video_path'];
$TARGET_PATH .= $video_path['name'];
if ($id == "" || $name == "" || $video_path['name'] == "")
{
$_SESSION['error'] = "All fields are required";
header("Location: index.php");
exit;
}
if (!is_valid_type($video_path))
{
$_SESSION['error'] = "You must upload a jpeg, gif,mp4 or bmp";
header("Location: index.php");
exit;
}
if (file_exists($TARGET_PATH))
{
$_SESSION['error'] = "A file with that name already exists";
header("Location: index.php");
exit;
}
if (move_uploaded_file($video_path['tmp_name'], $TARGET_PATH))
{
$sql = "insert into video (id, name, video_path) values ('$id', '$name', '" . $video_path['name'] . "')";
$result = mysql_query($sql) or die ("Could not insert data into DB: " . mysql_error());
header("Location: http://localhost:8888/htdocs/images.php");
exit;
}
else
{
$_SESSION['error'] = "Could not upload file. Check read/write persmissions on the directory";
header("Location: index.php");
exit;
}
?>
********* ********這是我的腳本顯示************
<?php
require("/Applications/MAMP/htdocs/conn.php");
?>
<html>
<head>
<title>tutorial</title>
</head>
<body>
<div>
<?php
$sql = "select * from video";
$result = mysql_query($sql) or die ("Could not access DB: " . mysql_error());
while ($row = mysql_fetch_assoc($result))
{
$src=$row['video_path'];
$path="http://localhost:8888/home/";
$home=$path.$src;
//echo "<video src=\"$home" ."\" height=\"200\" width=\"200\"/>";
echo $row['id'] . " " . $row['name'] . "<br />";
echo "</p>";
?>
<video width="320" height="240" controls>
<source src="<?php echo $home ?>" type="video/mp4" >
</video>
<?php
}
?>
</div>
</body>
</html>
**************** **這是我的表格腳本******** 夢在代碼教程
<style type="text/css">
label
{
float: left;
text-align: right;
margin-right: 10px;
width: 100px;
color: black;
}
#submit
{
float: left;
margin-top: 5px;
position: relative;
left: 110px;
}
#error
{
color: red;
font-weight: bold;
font-size: 16pt;
}
</style>
</head>
<body>
<div>
<?php
if (isset($_SESSION['error']))
{
echo "<span id=\"error\"><p>" . $_SESSION['error'] . "</p></span>";
unset($_SESSION['error']);
}
?>
<form action="upload.php" method="post" enctype="multipart/form-data">
<p>
<label>ID</label>
<input type="text" name="id" /><br />
<label>Video Name</label>
<input type="text" name="name" /><br />
<label>Upload Image</label>
<input type="file" name="video_path" /><br />
<input type="hidden" name="MAX_FILE_SIZE" value="100000000" />
<input type="submit" id="submit" value="Upload" />
</p>
</form>
</div>
</body>
查找在php.ini的'upload_max_filesize' http://stackoverflow.com/questions/2184513/php-change-the-maximum-upload-file-size – Mihai 2014-09-21 09:14:16
我認爲你最好的辦法是簽出視頻教程,如:https://www.youtube.com/watch?v=PRCobMXhnyw&list=PLfdtiltiRHWFVuW0b79nLbW25P340j1dT。這段代碼有很多錯誤。 1)硬編碼鏈接2)'mysql_ *'而不是'mysqli_ *'或'PDO' 3)使用if($ field =='')'而不是'if(empty($ field))'4) isset($ _ SESSION [])'而不是'!empty($ _ SESSION)'('empty()'與'isset()'相同,但也檢查它是否爲空)。像@Mihai說的那樣,在php.ini中查看最大上傳大小,其中有一些需要更改 – SuperDJ 2014-09-21 09:17:11
我能夠找到php.ini! – user3315446 2014-09-21 09:28:14