Jump to content

store uploaded video file in database.


zohab

Recommended Posts

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>

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

$_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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.