2014-03-24 128 views
0

我有一段代碼,我想編輯它,以便上傳的視頻顯示在我的網頁上,然後存儲在上傳文件夾中。 代碼:Php如何顯示視頻?

<?php 
$allowedExts = array("jpg", "jpeg", "gif", "png", "mp3", "mp4", "wma"); 
$allowType = array("video/mp4","audio/mp3","audio/wma","image/png","image/gif","image/jpeg"); 
$maxSize = 20000000000000; 
$extension = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION); 
$pathToUpload = 'upload/'; 

if(in_array($_FILES["file"]["type"], $allowType) && in_array($extension, $allowedExts) && $_FILES["file"]["size"] <= $maxSize) 
{ 
      if ($_FILES["file"]["error"] > 0) 
    { 
     echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; 
    } 
    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($pathToUpload . $_FILES["file"]["name"])) 
     { 
      echo $_FILES["file"]["name"] . " already exists. "; 
     } 
     else 
     { 
      move_uploaded_file($_FILES["file"]["tmp_name"], $pathToUpload . $_FILES["file"]["name"]); 
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; 
     } 
    } 
} 
else 
{ 
    echo "Invalid file"; 
} 

我不找人給我的代碼,但點我在正確的方向。

回答

0

點在哪裏視頻移動和你echo'ing它的位置:

"Stored in: " . "upload/" . $_FILES["file"]["name"]; 

,而不是echo'ing它存儲在那裏你可以把它添加到某種類型的視頻表:

$videoLocation = "upload/".$_FILES['file']['name']; 
// now insert $videoLocation into a database table 
//so you can fetch it on whatever page you feel like