mysql - Issue uploading WebM files using PHP

936

I want to be able to upload WebM files on my server from a simple upload script. I currently am able to successfully upload jpg's and png's to the server as well as write them to my sql database, but when using WebM, the file fails to be succesfully uploaded. However, it does create a filename and redirect me to that file, but it obviously doesn't exist. Here is the section of code for uploading WebM files. Any help would be appreciated.

                    if($file['type'] == "video/webm")
                    {
                        $seed = str_split('abcdefghijklmnopqrstuvwxyz'.'ABCDEFGHIJKLMNOPQRSTUVWXYZ'); // and any other characters
                        shuffle($seed);
                        $rand = '';
                        foreach (array_rand($seed, 6) as $k) 
                        $rand .= $seed[$k];
                        $filename = $rand.".webm";
                        $dir = "uploads/".$filename;

                        while(file_exists($dir))
                        {
                            $seed = str_split('abcdefghijklmnopqrstuvwxyz'.'ABCDEFGHIJKLMNOPQRSTUVWXYZ'); // and any other characters
                            shuffle($seed);
                            $rand = '';
                            foreach (array_rand($seed, 6) as $k) 
                            $rand .= $seed[$k];
                            $filename = $rand.".webm";
                            $dir = "u/".$filename;  
                        }
                            $host="localhost";
                            $username=""; 
                            $password=""; 
                            $db_name="removed"; 
                            $tbl_name="removed"; 
                            $ipaddress = $_SERVER['REMOTE_ADDR'];

                            mysql_connect("$host", "$username", "$password")or die("cannot connect server "); 
                            mysql_select_db("$db_name")or die("cannot select DB");

                            $datetime=date("y-m-d h:i:s");
                            $sql="INSERT INTO $tbl_name(filename, datetime)VALUES('$filename', '$datetime')";
                            $result=mysql_query($sql);
                            mysql_close();

                            move_uploaded_file($file['tmp_name'], $dir);
                            header( 'Location: u/'.$filename ) ;


                    }

I assume it has to do with the way I define the filetype, but i can't find any good information on the internet about it. Is video/webm the correct definition? I don't know.

Thanks.

People are also looking for solutions to the problem: php - jQuery: How to iterate through JSON encoded string (array)

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.