Welcome to WebmasterWorld Guest from 23.23.53.177

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)

5+ Year Member



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

5+ Year Member



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 Jun 9, 2008 (gmt 0)

5+ Year Member



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 Jun 9, 2008 (gmt 0)

5+ Year Member



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 Jun 10, 2008 (gmt 0)

5+ Year Member



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 Jun 10, 2008 (gmt 0)

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



you would probably need to add other filetypes to this line

$file_types_array=array("txt");

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

5+ Year Member



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 Jun 10, 2008 (gmt 0)

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



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 Jun 10, 2008 (gmt 0)

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



good point penders
 

Featured Threads

Hot Threads This Week

Hot Threads This Month