doo58088 2015-02-17 05:38
浏览 160
已采纳

如何使用PHP和MySQL在数据库中插入视频并在页面上获取

This is my code for uploading video on database or move to folder. In this code video uploaded but not insert file into database....??

please help me how to insert video in database using PHP + MySQL ?

<html>
<head>
</head>
 <body>
  <form ACTION="test.php" method="post" enctype="multipart/form-data">
  <label for="file">Filename:</label><br>
   <input type="file" name="video"><br>
   <input type="submit" name="submit" value="Submit">
   </form>
</body>
</html>

  <?php
    if(isset($_FILES['video']))
     {     
        $name = $_FILES['video']['name'];
        $type = explode('.',$name);
        $type = end($type);
        $size= $_FILES['video']['size'];
        $random_name = rand();
        $tmp= $_FILES['video']['tmp_name'];


       if($type !='mp4' && $type !='MP4' && $type !='flv')
       {
       $message ="Video Format Not Supported";
        }
       else
        {
        move_uploaded_file($tmp, 'videos/'.$random_name.'.'.$type);

       mysql_query("INSERT INTO 'videos' VALUES ('', '$name',   
        'videos/$random_name.$type')");

        $message ="Successfully Uploaded";
        }

         echo "$message <br/> <br/>";
        }
       ?>
  • 写回答

1条回答 默认 最新

  • duanchun6148 2015-02-17 06:47
    关注

    I copied this code from my file, hope this solves your problem.

    $vdo=$_FILES['uf']['name'];     $target_path = "video/";
    $target_path = $target_path . basename( $_FILES['uf']['name']);
    $target_path . basename( $_FILES['uf']['name']);
    if(move_uploaded_file($_FILES['uf']['tmp_name'], $target_path))
    {  $host="mysqlbhost.com";
    $username="me";
    $password="me";
    $db_name="db";
    $tbl_name="video";
    mysql_connect("$host", "$username", "$password")or die("cannot connect");
    mysql_select_db ("$db_name")or die("cannot select DB");
    $sql="INSERT INTO $tbl_name(video)
    VALUES('$vdo')";
    $result=mysql_query($sql);
    echo "<div id='rslt'>"; echo "Thanks! video has been sent to "; 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试