将视频上传到php中的目录

时间:2012-10-04 06:16:10

标签: php

这是我在目录中上传视频的代码。我在我的系统目录中存储了很多视频,名为D:/ video。我的问题很简单,如何从目录中获取存储的视频,我正在尝试但没有获取视频。你能帮助我吗 在此先感谢.......

                    上传图片     

// connect to the database 
include "connect1.php"; 
mysql_connect("$host", "$user", "$pass")
     or die("Could not connect: " . mysql_error());

     // select our database
     mysql_select_db("$db") or die(mysql_error());
        // the query that will add this to the database 
        // define the posted file into variables 
        echo $name = $_FILES['picture']['name']; 
        echo $tmp_name = $_FILES['picture']['tmp_name']; 
        echo $type = $_FILES['picture']['type']; 
        echo $size = $_FILES['picture']['size']; 

        // if your server has magic quotes turned off, add slashes manually 
        if(!get_magic_quotes_gpc()){ 
        $name = addslashes($name); 
        } 

        // open up the file and extract the data/content from it 
        $extract = fopen($tmp_name, 'r'); 
        $content = fread($extract, $size); 
        $content = addslashes($content); 
        fclose($extract);  



     if(!empty($_FILES)) 
    { 
        $target = "D:/videos/"; 
         $target = $target . basename( $_FILES['picture']['name']) ;
         echo $target;
        $addfile = "INSERT INTO video VALUES ('','$name', '$size', '$type','$target')"; 
        mysql_query($addfile) or die(mysql_error()); 



        echo "===========";
        echo $target;
        echo "===========";

        $ok=1; 
        if(move_uploaded_file($_FILES['picture']['tmp_name'], $target)) 
         {
         echo "The file ". basename( $_FILES['picture']['name']). " has been uploaded <br/>";
         } 
         else {
         echo "Sorry, there was a problem uploading your file.";
         }
    }



mysql_close();  

echo "Successfully uploaded your picture!";      
}else{die("No uploaded file present"); 
}   



?>
</head>

<body>

 <div align="center"> 

    <br /> 
    <a href="file.html">upload more images</a> 
</div> 

</body>
</html>

3 个答案:

答案 0 :(得分:1)

下面是如何从数据库中检索图像的答案

<?php $path = $row_getdetails['image']; ?>
<img src="<?php echo $path ?>"  alt="Image from DB" />

答案 1 :(得分:1)

尝试,

echo "<img src='".$target.$name."' />";

答案 2 :(得分:0)

上传后添加:

echo "<img src='".$target."' />";