masternick Posted May 31, 2008 Share Posted May 31, 2008 Hello I would like to make a Media section of my website so People can Register in the area and submit Videos in certain categories and can rate other peoples videos and even comment. I was wondering if anyone could help me since I am no good with PHP coding and phpMyAdmin Link to comment https://forums.phpfreaks.com/topic/108097-video-submitting-please-help/ Share on other sites More sharing options...
Gighalen Posted May 31, 2008 Share Posted May 31, 2008 Meh, I was just working on something like this for a client earlier today. How I did it was have the physical file uploaded to a directory, but save the LOCATION of the file into a DB table. This is my upload script: <form action="" method="post" enctype="multipart/form-data"> <table width="400" cellpadding="3" > <tr> <td colspan="2"> </td> </tr> <tr> <td width="120">1. Select a file »</td> <td width="280"><input type="file" name="uploaded_file" /></td> </tr> <tr> <td>2. Add Description</td> <td><textarea name="description"></textarea></td> </tr> <tr> <td>3. Upload</td> <td><input type="submit" name="sendForm" value="Upload File" /> <br /></td> </tr> </table> </form> <?php error_reporting(E_ALL ^ E_NOTICE); // Show all major errors. // Check to see if the button has been pressed if (!empty($_REQUEST['sendForm'])) { // Assign the name to a variable $name = $_FILES['uploaded_file']['name']; // Assign the tmp_name to a variable $tmp_name = $_FILES['uploaded_file']['tmp_name']; // Assign the error to a variable $error = $_FILES['uploaded_file']['error']; // Assign the size to a variable $size = $_FILES['uploaded_file']['size']; // No trailing// $uploadFilesTo = '../media'; // Create safe filename $name = ereg_replace('[^A-Za-z0-9.]', '-', $name); // Disallowed file extensions //what files you don't want upoad... leave this alone and you should be fine but you could add more $naughtyFileExtension = array("php", "php3", "asp", "inc", "txt", "wma","js", "exe", "jsp", "map", "obj", " ", "", "html", "cur", "ani"); // Returns an array that includes the extension $fileInfo = pathinfo($name); // Check extension if (!in_array($fileInfo['extension'], $naughtyFileExtension)) { // Get filename $name = getNonExistingFilename($uploadFilesTo, $name); // Upload the file if (move_uploaded_file($tmp_name, $uploadFilesTo.'/'.$name)) { $array = explode(".", $name); $type = $array[1]; $time = time(); $author = $session->username; $q = mysql_query("INSERT INTO files (id, author, type, name, description, time) VALUES ('', '$author', '$type', '$name', '$description', $time)"); // Show success message echo '<center><p>Your File has uploaded successfully<br />'.$uploadFilesTo.'/'.$name.'</p></center>'; } else { // Show failure message echo '<center><p>File failed to upload to /'.$name.'</p></center>'; } } else { // Bad File type echo '<center><p>The file uses an extension we don\'t allow.</p></center>'; } } // Functions do not need to be inline with the rest of the code function getNonExistingFilename($uploadFilesTo, $name) { if (!file_exists($uploadFilesTo . '/' . $name)) return $name; return getNonExistingFilename($uploadFilesTo, rand(100, 200) . '_' . $name); } ?> And the table: CREATE TABLE `files` ( `id` int(11) NOT NULL auto_increment, `author` varchar(64) default NULL, `type` varchar(40) default NULL, `name` varchar(128) default NULL, `description` blob, `time` varchar(32) default NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 How you retrieve the file names from the db is up to you, but I run a loop to select all the file names from the db, and then display them as a table with links to a page that will load the location of the file in the browser and play the file that way. Then all you have to do for a rating system is have another db table with each rating associated with the ID. Or just create another row in the first table. Idk. I hope this helped. Link to comment https://forums.phpfreaks.com/topic/108097-video-submitting-please-help/#findComment-554063 Share on other sites More sharing options...
Gighalen Posted May 31, 2008 Share Posted May 31, 2008 Oh sweet, it automatically cuts down the height of your coding boxes. Here, I will post my entire source. Upload.php <form action="" method="post" enctype="multipart/form-data"> <table width="400" cellpadding="3" > <tr> <td colspan="2"> </td> </tr> <tr> <td width="120">1. Select a file »</td> <td width="280"><input type="file" name="uploaded_file" /></td> </tr> <tr> <td>2. Add Description</td> <td><textarea name="description"></textarea></td> </tr> <tr> <td>3. Upload</td> <td><input type="submit" name="sendForm" value="Upload File" /> <br /></td> </tr> </table> </form> <?php error_reporting(E_ALL ^ E_NOTICE); // Show all major errors. // Check to see if the button has been pressed if (!empty($_REQUEST['sendForm'])) { // Assign the name to a variable $name = $_FILES['uploaded_file']['name']; // Assign the tmp_name to a variable $tmp_name = $_FILES['uploaded_file']['tmp_name']; // Assign the error to a variable $error = $_FILES['uploaded_file']['error']; // Assign the size to a variable $size = $_FILES['uploaded_file']['size']; // No trailing// $uploadFilesTo = '../media'; // Create safe filename $name = ereg_replace('[^A-Za-z0-9.]', '-', $name); // Disallowed file extensions //what files you don't want upoad... leave this alone and you should be fine but you could add more $naughtyFileExtension = array("php", "php3", "asp", "inc", "txt", "wma","js", "exe", "jsp", "map", "obj", " ", "", "html", "cur", "ani"); // Returns an array that includes the extension $fileInfo = pathinfo($name); // Check extension if (!in_array($fileInfo['extension'], $naughtyFileExtension)) { // Get filename $name = getNonExistingFilename($uploadFilesTo, $name); // Upload the file if (move_uploaded_file($tmp_name, $uploadFilesTo.'/'.$name)) { $array = explode(".", $name); $type = $array[1]; $time = time(); $author = $session->username; $q = mysql_query("INSERT INTO files (id, author, type, name, description, time) VALUES ('', '$author', '$type', '$name', '$description', $time)"); // Show success message echo '<center><p>Your File has uploaded successfully<br />'.$uploadFilesTo.'/'.$name.'</p></center>'; } else { // Show failure message echo '<center><p>File failed to upload to /'.$name.'</p></center>'; } } else { // Bad File type echo '<center><p>The file uses an extension we don\'t allow.</p></center>'; } } // Functions do not need to be inline with the rest of the code function getNonExistingFilename($uploadFilesTo, $name) { if (!file_exists($uploadFilesTo . '/' . $name)) return $name; return getNonExistingFilename($uploadFilesTo, rand(100, 200) . '_' . $name); } ?> Videos.php <p class="header">Video Archive</p> <?php $q = mysql_query("SELECT * FROM photos"); $num = mysql_num_rows($q); if($num == 0){ echo "<br><br><br><center>No photos uploaded yet! Check back soon!<center>"; } else { $query = mysql_query("SELECT * FROM files"); $i = 0; echo "<table align=\"center\">"; while($data = mysql_fetch_array($query)){ if($col == 0){ echo "<tr>"; } echo "<td onclick=\"parent.location.href='viewvideo.php?id=".$data['id']."'\" width=\"125px\" height=\"100px\" style=\"border:1px #000000 solid;\"><img src=\"images/movies.png\" width=\"123px\" height=\"98px\"></td>"; if($col == 3){ echo "</tr>"; $i = 0; $num--; } else { $i--; $col++; } } } echo "</table>"; ?> Viewvideo.php <?php $id = $_GET['id']; $q = mysql_query("SELECT * FROM files WHERE id = '$id'"); $data = mysql_fetch_array($q); echo " <center> <object id=\"MediaPlayer1\" width=\"450\" height=\"450\" standby=\"Loading Windows Media Player components...\" data=\"media/".$data['name']."\" type=\"application/x-mplayer2\" title=\"Title of this video object\" style=\"background-color: #000000;\" > <param name=\"filename\" value=\"media/".$data['name']."\" /> <param name=\"height\" value=\"450\" /> <param name=\"width\" value=\"450\" /> <param name=\"autoStart\" value=\"1\" /> <param name=\"autoPlay\" value=\"1\" /> <param name=\"AnimationatStart\" value=\"1\" /> <param name=\"showdisplay\" value=\"0\" /> <param name=\"TransparentAtStart\" value=\"0\" /> <param name=\"ShowControls\" value=\"1\" /> <param name=\"ShowStatusBar\" value=\"1\" /> <param name=\"ClickToPlay\" value=\"0\" /> <param name=\"bgcolor\" value=\"#000000\" /> <param name=\"volume\" value=\"100%\" /> <param name=\"InvokeURLs\" value=\"0\" /> <param name=\"loop\" value=\"0\" /> <em>Description of this video object</em> </object> </center> "; ?> Lastly, the DB table: CREATE TABLE `files` ( `id` int(11) NOT NULL auto_increment, `author` varchar(64) default NULL, `type` varchar(40) default NULL, `name` varchar(128) default NULL, `description` blob, `time` varchar(32) default NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 You may have to change a few of the URL's around here and there, but just look over it and you will see that it's very easy to edit. Link to comment https://forums.phpfreaks.com/topic/108097-video-submitting-please-help/#findComment-554064 Share on other sites More sharing options...
Gighalen Posted May 31, 2008 Share Posted May 31, 2008 Correction on videos.php: <p class="header">Video Archive</p> <?php $q = mysql_query("SELECT * FROM files"); $num = mysql_num_rows($q); if($num == 0){ echo "<br><br><br><center>No Videos uploaded yet! Check back soon!<center>"; } else { $query = mysql_query("SELECT * FROM files"); $i = 0; echo "<table align=\"center\">"; while($data = mysql_fetch_array($query)){ if($col == 0){ echo "<tr>"; } echo "<td onclick=\"parent.location.href='viewvideo.php?id=".$data['id']."'\" width=\"125px\" height=\"100px\" style=\"border:1px #000000 solid;\"><img src=\"images/movies.png\" width=\"123px\" height=\"98px\"></td>"; if($col == 3){ echo "</tr>"; $i = 0; $num--; } else { $i--; $col++; } } } echo "</table>"; ?> Link to comment https://forums.phpfreaks.com/topic/108097-video-submitting-please-help/#findComment-554065 Share on other sites More sharing options...
masternick Posted May 31, 2008 Author Share Posted May 31, 2008 Where do I put the Database (DB) information? In phpmyadmin?????????? or Mysql, will i have to make a new database then do the DataBase infromation in phpmyadmin? thanks MasterNick Link to comment https://forums.phpfreaks.com/topic/108097-video-submitting-please-help/#findComment-554071 Share on other sites More sharing options...
liamloveslearning Posted May 31, 2008 Share Posted May 31, 2008 You can execute the .sql file in phpmyadmin i think, there should be a text area where you key in the db info CREATE TABLE `files` ( `id` int(11) NOT NULL auto_increment, `author` varchar(64) default NULL, `type` varchar(40) default NULL, `name` varchar(128) default NULL, `description` blob, `time` varchar(32) default NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 then "execute" or "run", im not to sure where it is in phpmyadmin tho, you should be able to google it Link to comment https://forums.phpfreaks.com/topic/108097-video-submitting-please-help/#findComment-554084 Share on other sites More sharing options...
masternick Posted May 31, 2008 Author Share Posted May 31, 2008 What do you mean???? Do i have to make a sql file??? If so where?? Can you please write out some steps on how to make a database??? and then do the php my admin? Link to comment https://forums.phpfreaks.com/topic/108097-video-submitting-please-help/#findComment-554161 Share on other sites More sharing options...
liamloveslearning Posted May 31, 2008 Share Posted May 31, 2008 do you have a web host? and does it support mySQL ? you have to contact your host provider and find out your database details and if its supported; they will then provide you with your details Link to comment https://forums.phpfreaks.com/topic/108097-video-submitting-please-help/#findComment-554208 Share on other sites More sharing options...
masternick Posted June 1, 2008 Author Share Posted June 1, 2008 Yes I do have a host, It supports Mysql and PHP but does the Mysql have to be 5+??? If you have some spare tima could I give you the details of my host and you help me do it????? thanks very very much. MasterNick Link to comment https://forums.phpfreaks.com/topic/108097-video-submitting-please-help/#findComment-554594 Share on other sites More sharing options...
Gighalen Posted June 1, 2008 Share Posted June 1, 2008 That is a very basic query. You could probally use it even with MySQL 1.0 lol. If there was a 1.0. You need to do it yourself. Go to the MySQL forum and ask how to access your MySQL panel and run basic create table queries. If all else fails, you can always IM me on MSN or AIM. Link to comment https://forums.phpfreaks.com/topic/108097-video-submitting-please-help/#findComment-554598 Share on other sites More sharing options...
TheFilmGod Posted June 1, 2008 Share Posted June 1, 2008 Basically, you need to create a connect.php file. This contains information on how to connect to mysql. Once you connect, everything is pretty easy. I use godaddy and they automatically create this file for you. I"m sure your host does something similar, so call them up and find out. Link to comment https://forums.phpfreaks.com/topic/108097-video-submitting-please-help/#findComment-554602 Share on other sites More sharing options...
masternick Posted June 1, 2008 Author Share Posted June 1, 2008 If I give you the details to my host could you please help me, I am not good at this stuff, please. Nick Link to comment https://forums.phpfreaks.com/topic/108097-video-submitting-please-help/#findComment-554611 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.