zohab Posted September 10, 2012 Share Posted September 10, 2012 Hi, I am able to upload image file and store in database. I am not able to upload video files in database. I have increase file upload limit and related settings in php.ini Thanks Zohaib. <?php error_reporting(E_ALL); /* Table Create Table ------ ---------------------------------------------------------- upload CREATE TABLE `upload` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(30) CHARACTER SET utf8 DEFAULT NULL, `type` varchar(30) CHARACTER SET utf8 DEFAULT NULL, `size` int(11) DEFAULT '0', `content` longblob, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=16 DEFAULT CHARSET=latin1 */ $dbhost = 'localhost'; $dbuser = 'user'; $dbpass = 'password'; $dbname = 'fileupload'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql'); mysql_select_db($dbname); if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $fp = fopen($tmpName, 'r'); $content = fread($fp, filesize($tmpName)); $content = addslashes($content); fclose($fp); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } /* echo "<br/>".$fileName; echo "<br/>".$fileSize; echo "<br/>".$fileType; //echo "<br/>".$content; */ $query = "INSERT INTO upload (name, size, type, content ) "."VALUES ('$fileName', '$fileSize', '$fileType', '$content')"; mysql_query($query) or die('Error, query failed'); mysql_close($conn); echo "File $fileName uploaded"; } ?> <form method="post" enctype="multipart/form-data"> <table width="350" border="0" cellpadding="1" cellspacing="1" class="box"> <tr> <td width="246"> <input type="hidden" name="MAX_FILE_SIZE" value="2000000"> <input name="userfile" type="file" id="userfile"> </td> <td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td> </tr> </table> </form> Quote Link to comment https://forums.phpfreaks.com/topic/268227-store-uploaded-video-file-in-database/ Share on other sites More sharing options...
Spring Posted September 10, 2012 Share Posted September 10, 2012 What? Gonna need more info. Quote Link to comment https://forums.phpfreaks.com/topic/268227-store-uploaded-video-file-in-database/#findComment-1376775 Share on other sites More sharing options...
Jessica Posted September 10, 2012 Share Posted September 10, 2012 Files should be stored in the filesystem Quote Link to comment https://forums.phpfreaks.com/topic/268227-store-uploaded-video-file-in-database/#findComment-1376777 Share on other sites More sharing options...
zohab Posted September 10, 2012 Author Share Posted September 10, 2012 filesystem may i get an example? Quote Link to comment https://forums.phpfreaks.com/topic/268227-store-uploaded-video-file-in-database/#findComment-1376778 Share on other sites More sharing options...
premiso Posted September 10, 2012 Share Posted September 10, 2012 Storing something as big as a video in a MySQL database in inefficient to say the least and not recommended by any means. It would be better to store the video information (such as path to video) in the database and keep the video on your file system (IE inside of a folder on the computer). This will yield much better performance than putting it in the database and probably cause you a ton less headaches, such as MySQL being completely overloaded by 5 people trying to grab different videos at a time and locking up the database. Or a script inserting 1 video and creating a write lock on the DB. Quote Link to comment https://forums.phpfreaks.com/topic/268227-store-uploaded-video-file-in-database/#findComment-1376779 Share on other sites More sharing options...
Jessica Posted September 10, 2012 Share Posted September 10, 2012 Where you put all the files. Also, see below. Quote Link to comment https://forums.phpfreaks.com/topic/268227-store-uploaded-video-file-in-database/#findComment-1376780 Share on other sites More sharing options...
zohab Posted September 11, 2012 Author Share Posted September 11, 2012 Hi, I want everything files ,images,documents ,videos in database. $_FILES not working with videos and I need example to upload video files in database. Thanks Zohaib. Quote Link to comment https://forums.phpfreaks.com/topic/268227-store-uploaded-video-file-in-database/#findComment-1376942 Share on other sites More sharing options...
Jessica Posted September 11, 2012 Share Posted September 11, 2012 Wanting something does not make it a good idea. Quote Link to comment https://forums.phpfreaks.com/topic/268227-store-uploaded-video-file-in-database/#findComment-1377012 Share on other sites More sharing options...
PFMaBiSmAd Posted September 11, 2012 Share Posted September 11, 2012 $_FILES not working with videos That's because the size of the file is exceeding the post_max_size setting and the $_FILES and $_POST arrays are empty. To upload large files, you must increase the post_max_size and upload_max_filesize settings and you should be testing if a POST method form as been submitted and if the $_FILES and $_POST arrays are empty, to detect this condition and output an appropriate message to the user. Quote Link to comment https://forums.phpfreaks.com/topic/268227-store-uploaded-video-file-in-database/#findComment-1377013 Share on other sites More sharing options...
zohab Posted September 16, 2012 Author Share Posted September 16, 2012 Hi , I set following in php.ini configuration and restart server upload_max_filesize 300M 300M max_execution_time 600 600 memory_limit 500M 500M upload_max_filesize 300M 300M When I upload video file then I am getting following message. error_reporting(E_ALL); echo"<pre>"; print_r($_POST); echo"</pre>"; echo"<pre>"; print_r($_FILES); echo"</pre>"; echo"<pre>"; print_r($_FILES['userfile']['error']); echo"</pre>"; Array ( [MAX_FILE_SIZE] => 2000000 [upload] => Upload ) Array ( [userfile] => Array ( [name] => Video.FLV [type] => [tmp_name] => [error] => 2 => 0 ) ) 2 Same code work fine for images.documents upload. Any solution for this problem in uploading videos in mysql database from php - Thanks Zohaib. Quote Link to comment https://forums.phpfreaks.com/topic/268227-store-uploaded-video-file-in-database/#findComment-1378305 Share on other sites More sharing options...
Christian F. Posted September 16, 2012 Share Posted September 16, 2012 You know, the PHP Manual explains that quite nicely. It doesn't take long to check it when you have problems, and by doing so you won't have to wait for other people to have the time and desire to help you out. PS: Storing the videos in the database itself is still a bad idea. Quote Link to comment https://forums.phpfreaks.com/topic/268227-store-uploaded-video-file-in-database/#findComment-1378309 Share on other sites More sharing options...
hakimserwa Posted September 16, 2012 Share Posted September 16, 2012 Hi, I want everything files ,images,documents ,videos in database. $_FILES not working with videos and I need example to upload video files in database. Thanks Zohaib. hey decide on one thing you came here for help on something that failed you so use this chance and grab that help. these people here have a lot of thing that they can do with there precious time and it seem you dont appreciate that. love to learn thats the best way to go. Quote Link to comment https://forums.phpfreaks.com/topic/268227-store-uploaded-video-file-in-database/#findComment-1378313 Share on other sites More sharing options...
zohab Posted September 17, 2012 Author Share Posted September 17, 2012 I did this using JSP and Oracle Database easily. Also I have solution for same in .NET I understand that people suggest storing video in mysql database in not good idea But this is the first time in years of experience I found storing video using PHP and MySQL getting difficult for expert in forum also. I have seen many .NET and J2EE applications where video files stored in database. I appreciate people coming to this post and trying to post solution and I want to say thank for their time. I am actually not able to find way to store video in mysql DB and using PHP and need solution. Thanks ChristianF for the link - Thanks Zohaib. Quote Link to comment https://forums.phpfreaks.com/topic/268227-store-uploaded-video-file-in-database/#findComment-1378616 Share on other sites More sharing options...
zohab Posted September 17, 2012 Author Share Posted September 17, 2012 Thanks ChristianF for the link Quote Link to comment https://forums.phpfreaks.com/topic/268227-store-uploaded-video-file-in-database/#findComment-1378618 Share on other sites More sharing options...
Jessica Posted September 17, 2012 Share Posted September 17, 2012 It's not difficult for us to tell you how, it's just a bad idea. Quote Link to comment https://forums.phpfreaks.com/topic/268227-store-uploaded-video-file-in-database/#findComment-1378640 Share on other sites More sharing options...
Christian F. Posted September 17, 2012 Share Posted September 17, 2012 The problem you've having is not related to MySQL at all, but happens quite a bit before the database is involved. As evidenced by the error code you're given. You're welcome, and I hope you've figured it out by now. Quote Link to comment https://forums.phpfreaks.com/topic/268227-store-uploaded-video-file-in-database/#findComment-1378741 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.