How to upload videos in database?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hemaldazzle
    New Member
    • Jul 2012
    • 15

    How to upload videos in database?

    I don,t know how can upload videos in database and retrive
    to the database

    Videos cant save in videos folder.

    ------
    update

    so what can i do which place i change
    Code:
    <?php
    
    if ($_POST["action"] == "Load")
    {
    $folder = "videos/";
    
    
    
    move_uploaded_file($_FILES["filep"]["tmp_name"] , "$folder".$_FILES["filep"]["name"]);
    
    echo "<p align=center>File ".$_FILES["filep"]["name"]."loaded...";
    
    $result = mysql_connect("localhost", "root", "") or die ("Could not save  name Error: " . mysql_error());
    mysql_select_db("v1") or die("Could not select database");
    mysql_query("INSERT into video (URL) VALUES('".$_FILES['filep']['name']."')");
    
    if($result) { echo "Video name saved into database"; 
    	echo "<a href='retrivevideos.php'><input type='button' value='Retrive'></a>";
    }
    else {
    
    //Gives and error if its not
    echo "Sorry, there was a problem uploading your file.";
    }
    }
    ?>
    Last edited by Niheel; Jul 25 '12, 05:35 AM.
  • lyodmichael
    New Member
    • Jul 2012
    • 75

    #2
    you dont need to upload the upload the video you just need to get the address and save it in database.

    Comment

    • Exequiel
      Contributor
      • Jul 2012
      • 288

      #3
      if you already tried to upload an image, the way on how to upload an image is just the same on how to upload a video. Only the file extension is the difference.

      Comment

      • Exequiel
        Contributor
        • Jul 2012
        • 288

        #4
        Code:
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html xmlns="http://www.facebook.com/exequiel.s.vibar">
        <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Sampol upload ni zick</title>
        </head>
        <?php
        include'connect_to_db.php';//connection to database
        ?>
        <body>
        <br><br>
        <center>
        <?php
        //code for uploading videos...
        if(isset($_POST['video'])){//button for Upload
        $target = "uploaded_folder/"; //folder where to save the uploaded file/video
         $target = $target . basename( $_FILES['uploaded']['name']) ; //gets the name of the upload file
         $ok=1; 
         if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 
         {
        	 $query =mysql_query( "INSERT INTO tbl_video(video_name) VALUES ('$target')");//insertion to database
        	 
         echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
         } 
         else {
         echo "Sorry, there was a problem uploading your file.";
         }
        }
         ?>
        
         <form enctype="multipart/form-data" method="POST">
        	 Please choose a file: <input name="uploaded" type="file" /><br />
        	 <input type="submit" value="Upload" name="video"/>
         </form> 
        
        <br><br>
        <br>
        </center>
        </body>
        </html>
        you can upload any files in this code, because we did not restrict the file extension...

        Comment

        • hemaldazzle
          New Member
          • Jul 2012
          • 15

          #5
          ok thanks Exequiel for given code.

          how i retrieve video in database if any idea or code please give me

          Comment

          • hemaldazzle
            New Member
            • Jul 2012
            • 15

            #6
            hay Exequiel in this code do not upload videos?why
            and not save path in database but any other file uploaded

            Comment

            • Murat Bastas
              New Member
              • Jul 2012
              • 25

              #7
              hemaldazzle it works.
              include'connect _to_db.php';
              maybe, error in this line.

              Comment

              • sharmahemal
                New Member
                • Jul 2012
                • 19

                #8
                yes that is work but not upload video in upload folder and database

                Comment

                • Murat Bastas
                  New Member
                  • Jul 2012
                  • 25

                  #9
                  you check file upload limit. it should work.

                  Comment

                  • Exequiel
                    Contributor
                    • Jul 2012
                    • 288

                    #10
                    Code:
                    <?php
                    $con=mysql_connect("localhost","root","") or die ("COULD NOT CONNECT TO YOUR DATABASE!");
                    mysql_select_db("upload_sample",$con);
                    ?>
                    try this code for the connection to your database, save it as connect_to_db.p hp,

                    Comment

                    • Exequiel
                      Contributor
                      • Jul 2012
                      • 288

                      #11
                      you can retrieve the video in db by its file name and Id. and you must set the destination of your uploaded file, example,

                      ../uploaded_folder/$var_for_filena me; //the destination where the uploaded file(s) being saved and its file name. try it in sql .

                      Comment

                      • Exequiel
                        Contributor
                        • Jul 2012
                        • 288

                        #12
                        Download this file. . . http://www.mediafire.com/?1iyj7efan98jj0a. . . and try to run. . .:)

                        Comment

                        • computerfox
                          Contributor
                          • Mar 2010
                          • 276

                          #13
                          I was actually just about to say that. I don't suggest uploading a video into a database as in a multimedia database because you would need to use a blob, which is difficult to deal with. You'll want to use that form script that was provided, make sure that you allow users to upload the correct size for the files, make sure that the directory is read/write=777, and you copy the URL into the database as a text. What I even suggest is maybe generating a random name before completing the script (this would most likely require a rename at the end of the script), but this part is not mandatory. All you really need is the file name and know where the videos would be stored.

                          Hope that helps!

                          Comment

                          Working...