By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,882 Members | 928 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,882 IT Pros & Developers. It's quick & easy.

How to upload videos in database?

P: 15
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
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. if ($_POST["action"] == "Load")
  4. {
  5. $folder = "videos/";
  6.  
  7.  
  8.  
  9. move_uploaded_file($_FILES["filep"]["tmp_name"] , "$folder".$_FILES["filep"]["name"]);
  10.  
  11. echo "<p align=center>File ".$_FILES["filep"]["name"]."loaded...";
  12.  
  13. $result = mysql_connect("localhost", "root", "") or die ("Could not save  name Error: " . mysql_error());
  14. mysql_select_db("v1") or die("Could not select database");
  15. mysql_query("INSERT into video (URL) VALUES('".$_FILES['filep']['name']."')");
  16.  
  17. if($result) { echo "Video name saved into database"; 
  18.     echo "<a href='retrivevideos.php'><input type='button' value='Retrive'></a>";
  19. }
  20. else {
  21.  
  22. //Gives and error if its not
  23. echo "Sorry, there was a problem uploading your file.";
  24. }
  25. }
  26. ?>
Jul 24 '12 #1

✓ answered by Exequiel

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.facebook.com/exequiel.s.vibar">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Sampol upload ni zick</title>
  6. </head>
  7. <?php
  8. include'connect_to_db.php';//connection to database
  9. ?>
  10. <body>
  11. <br><br>
  12. <center>
  13. <?php
  14. //code for uploading videos...
  15. if(isset($_POST['video'])){//button for Upload
  16. $target = "uploaded_folder/"; //folder where to save the uploaded file/video
  17.  $target = $target . basename( $_FILES['uploaded']['name']) ; //gets the name of the upload file
  18.  $ok=1; 
  19.  if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 
  20.  {
  21.      $query =mysql_query( "INSERT INTO tbl_video(video_name) VALUES ('$target')");//insertion to database
  22.  
  23.  echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
  24.  } 
  25.  else {
  26.  echo "Sorry, there was a problem uploading your file.";
  27.  }
  28. }
  29.  ?>
  30.  
  31.  <form enctype="multipart/form-data" method="POST">
  32.      Please choose a file: <input name="uploaded" type="file" /><br />
  33.      <input type="submit" value="Upload" name="video"/>
  34.  </form> 
  35.  
  36. <br><br>
  37. <br>
  38. </center>
  39. </body>
  40. </html>
you can upload any files in this code, because we did not restrict the file extension...

Share this Question
Share on Google+
12 Replies


P: 75
you dont need to upload the upload the video you just need to get the address and save it in database.
Jul 24 '12 #2

Exequiel
100+
P: 287
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.
Jul 24 '12 #3

Exequiel
100+
P: 287
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.facebook.com/exequiel.s.vibar">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Sampol upload ni zick</title>
  6. </head>
  7. <?php
  8. include'connect_to_db.php';//connection to database
  9. ?>
  10. <body>
  11. <br><br>
  12. <center>
  13. <?php
  14. //code for uploading videos...
  15. if(isset($_POST['video'])){//button for Upload
  16. $target = "uploaded_folder/"; //folder where to save the uploaded file/video
  17.  $target = $target . basename( $_FILES['uploaded']['name']) ; //gets the name of the upload file
  18.  $ok=1; 
  19.  if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 
  20.  {
  21.      $query =mysql_query( "INSERT INTO tbl_video(video_name) VALUES ('$target')");//insertion to database
  22.  
  23.  echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
  24.  } 
  25.  else {
  26.  echo "Sorry, there was a problem uploading your file.";
  27.  }
  28. }
  29.  ?>
  30.  
  31.  <form enctype="multipart/form-data" method="POST">
  32.      Please choose a file: <input name="uploaded" type="file" /><br />
  33.      <input type="submit" value="Upload" name="video"/>
  34.  </form> 
  35.  
  36. <br><br>
  37. <br>
  38. </center>
  39. </body>
  40. </html>
you can upload any files in this code, because we did not restrict the file extension...
Jul 26 '12 #4

P: 15
ok thanks Exequiel for given code.

how i retrieve video in database if any idea or code please give me
Jul 26 '12 #5

P: 15
hay Exequiel in this code do not upload videos?why
and not save path in database but any other file uploaded
Jul 26 '12 #6

Murat Bastas
P: 25
hemaldazzle it works.
include'connect_to_db.php';
maybe, error in this line.
Jul 26 '12 #7

P: 19
yes that is work but not upload video in upload folder and database
Jul 26 '12 #8

Murat Bastas
P: 25
you check file upload limit. it should work.
Jul 26 '12 #9

Exequiel
100+
P: 287
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $con=mysql_connect("localhost","root","") or die ("COULD NOT CONNECT TO YOUR DATABASE!");
  3. mysql_select_db("upload_sample",$con);
  4. ?>
try this code for the connection to your database, save it as connect_to_db.php,
Jul 27 '12 #10

Exequiel
100+
P: 287
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_filename; //the destination where the uploaded file(s) being saved and its file name. try it in sql .
Jul 27 '12 #11

Exequiel
100+
P: 287
Download this file. . . http://www.mediafire.com/?1iyj7efan98jj0a. . . and try to run. . .:)
Jul 27 '12 #12

computerfox
100+
P: 278
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!
Jul 30 '12 #13

Post your reply

Sign in to post your reply or Sign up for a free account.