如何使用mysql数据库将视频上传到php目录中 [英] how to upload videos to directory in php using mysql database

查看:82
本文介绍了如何使用mysql数据库将视频上传到php目录中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在这里是siddu,对PHP还是陌生的,我在这里给出了用于上传视频但不超过4MB的代码.所以你能帮我吗?

在此先感谢

hi everyone,

I am siddu here and am new to PHP, I have given code here which is used to upload video but not more than 4MB. So can you please help me out.

Thanks in advance

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title> Upload Image </title>
    <?php
    // if something was posted, start the process...
    if(isset($_POST['upload']))
    {
    
    
    
    // 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>

推荐答案

_POST [' 上传'])) { // 连接到数据库 包括" ; mysql_connect("
_POST['upload'])) { // connect to the database include "connect1.php"; mysql_connect("


主机" ,"
host", "


用户",
user", "


这篇关于如何使用mysql数据库将视频上传到php目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆