Welcome to WebmasterWorld Guest from 54.144.107.83

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

upload video file using PHP-Mysql

upload small videofiles in php and store them in db using mysql

     
5:17 am on Jun 9, 2008 (gmt 0)

New User

5+ Year Member

joined:June 9, 2008
posts:21
votes: 0


Hi,
I am using php4.Please tell me how we can upload small video files using php.
8:47 am on June 9, 2008 (gmt 0)

Junior Member

5+ Year Member

joined:Aug 7, 2007
posts:103
votes: 0


You can find a tutorial on the subject of uploading content by googling: tizag.com upload

The tutorial points this as well but remember that the script presented there is not very safe and you should do some checking on the files to be uploaded.

10:57 am on June 9, 2008 (gmt 0)

New User

5+ Year Member

joined:June 9, 2008
posts:21
votes: 0


Hi,

I went through the google:tizag.com.But i didnt found the files for uploading the videos.Can u provide me some more information.I successfully uploaded the images but the videos will not be uploaded.

12:36 pm on June 9, 2008 (gmt 0)

Preferred Member

10+ Year Member

joined:Aug 6, 2005
posts:575
votes: 0


I successfully uploaded the images but the videos will not be uploaded.

I'd have thought that the only difference between uploading images and videos would be the file size. I would firstly check whether your server's maximum file upload size is the problem.

5:31 am on June 10, 2008 (gmt 0)

New User

5+ Year Member

joined:June 9, 2008
posts:21
votes: 0


Hi,
I successfully uploaded the .txt file but here is the problem is the extensions.So,plz tell me how can i change it as video extension like mpeg.Here is my complete code.

<?

$num_of_uploads=1;
$file_types_array=array("txt");
$max_file_size=1048576;
$upload_dir="";
if(!is_numeric($max_file_size)){
$max_file_size = 1048576;
}
if(!isset($_POST["submitted"])){
$upload1="upload1.php";
$form = "<form action='".$upload1."' method='post' enctype='multipart/form-data'>Upload files:<br /><input type='hidden' name='submitted' value='TRUE' id='".time()."'><input type='hidden' name='MAX_FILE_SIZE' value='".$max_file_size."'>";
for($x=0;$x<$num_of_uploads;$x++){
$form .= "<input type='file' name='file[]'><font color='red'>*</font><br />";
}
$form .= "<input type='submit' value='Upload'><br /><font color='red'>*</font>Maximum file length (minus extension) is 15 characters. Anything over that will be cut to only 15 characters. Valid file type(s): ";
for($x=0;$x<count($file_types_array);$x++){
if($x<count($file_types_array)-1){
$form .= $file_types_array[$x].", ";
}else{
$form .= $file_types_array[$x].".";
}
}
$form .= "</form>";
echo($form);
}else{
foreach($_FILES["file"]["error"] as $key => $value){
if($_FILES["file"]["name"][$key]!=""){
if($value==UPLOAD_ERR_OK){
$origfilename = $_FILES["file"]["name"][$key];
$filename = explode(".", $_FILES["file"]["name"][$key]);
$filenameext = $filename[count($filename)-1];
unset($filename[count($filename)-1]);
$filename = implode(".", $filename);
$filename = substr($filename, 0, 15).".".$filenameext;
$file_ext_allow = FALSE;
for($x=0;$x<count($file_types_array);$x++){
if($filenameext==$file_types_array[$x]){
$file_ext_allow = TRUE;
}
}
if($file_ext_allow){
if($_FILES["file"]["size"][$key]<$max_file_size){
if(move_uploaded_file($_FILES["file"]["tmp_name"][$key], $upload_dir.$filename)){
echo("File uploaded successfully. - <a href='".$upload_dir.$filename."' target='_blank'>".$filename."</a><br />");
}else{
echo($origfilename." was not successfully uploaded<br />");
}
}else{
echo($origfilename." was too big, not uploaded<br />");
}
}else{
echo($origfilename." had an invalid file extension, not uploaded<br />");
}
}else{
echo($origfilename." was not successfully uploaded<br />");
}
}
}
}

?>

11:55 am on June 10, 2008 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15755
votes: 0


you would probably need to add other filetypes to this line

$file_types_array=array("txt");

11:56 am on June 10, 2008 (gmt 0)

Preferred Member

10+ Year Member

joined:Aug 6, 2005
posts:575
votes: 0


EDIT: Beaten to it!

Only had a quick look, but I think you just need to add the MPEG file extension to your file types array:

$file_types_array=array("txt", "mpg");
12:53 pm on June 10, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:July 3, 2006
posts: 3123
votes: 0


upload small videofiles in php and store them in db using mysql

Just to note... you probably don't want to actually store the video in the db. It would be more likely to store just the filename in the db and the video file on the filesystem - which is probably what you are doing.

1:08 pm on June 10, 2008 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15755
votes: 0


good point penders