/include/video.php

https://bitbucket.org/ulisesrodriguez/imgvid · PHP · 241 lines · 131 code · 84 blank · 26 comment · 42 complexity · eef58f275fcdb9a492d9e6e8527c32ee MD5 · raw file

  1. <?php
  2. // Include Files
  3. require 'settings.php';
  4. // Class Videos
  5. class Videos{
  6. // Atributes
  7. // Save return data
  8. private $data = array();
  9. // Directory
  10. private $directory = '../videos/files/';
  11. // Video Public access
  12. public $video = null;
  13. // Conection
  14. private $conection = null;
  15. // Methods
  16. // Construct Clena Vars
  17. public function __construct(){
  18. // Clean data
  19. unset( $this->data );
  20. $this->data = array();
  21. // Valid Directory
  22. if( !is_dir( $this->directory ) ){ echo '<h1>Does don\'t exist that directory: '.$this->directory.'</h1>'; exit; }
  23. $this->conection = new Settings();
  24. $this->video = null;
  25. }
  26. // Create Video
  27. public function create(){
  28. // Valid video format and setting codecs
  29. if ( $_FILES['video']['type'] != "video/avi"
  30. and $_FILES['video']['type'] != "video/mp4"
  31. and $_FILES['video']['type'] != "video/webm"
  32. and $_FILES['video']['type'] != "video/x-ms-wmv"
  33. and $_FILES['video']['type'] != "video/x-msvideo"
  34. and $_FILES['video']['type'] != "video/mpeg"
  35. and $_FILES['video']['type'] != "video/quicktime"
  36. and $_FILES['video']['type'] != "video/x-msvideo"
  37. and $_FILES['video']['type'] != "video/x-flv"
  38. and $_FILES['video']['type'] != "application/octet-stream"
  39. and $_FILES['video']['type'] != "application/x-shockwave-flash" )return false;
  40. // Upload file
  41. $file = explode( '.', $_FILES['video']['name'] );
  42. $name = strtolower( $file[0] );
  43. $name = str_replace( '/', '-', $name );
  44. $name = str_replace( ' ', '-', $name );
  45. move_uploaded_file( $_FILES['video']['tmp_name'], $this->directory . $name.'.'.$file[1] );
  46. $sql = 'INSERT INTO `videos`( `id`, `name` )';
  47. $sql .= 'VALUES( null, \''.strip_tags( $name.'.'.$file[1] ).'\');';
  48. $res = mysql_query( $sql, $this->conection->con() );
  49. $this->video = strip_tags( $name.'.'.$file[1] );
  50. if( !empty( $res ) )
  51. return true;
  52. else
  53. return false;
  54. }
  55. // Update Video
  56. public function show( $id = 0 ){
  57. // Valid id
  58. if( empty( $id ) ) return false;
  59. if( !is_numeric( $id ) ) return false;
  60. // Return Old Video
  61. $sql = 'SELECT `name`';
  62. $sql .= 'FROM `videos`';
  63. $sql .= 'WHERE `id`=\''.strip_tags( $id ).'\' LIMIT 1;';
  64. $res = mysql_query( $sql, $this->conection->con() );
  65. if( $reg = mysql_fetch_assoc( $res ) ){
  66. $this->data[] = $reg;
  67. $this->video = $this->directory . $this->data[0]['name'];
  68. }else
  69. return false;
  70. }
  71. // Update Video
  72. public function edit( $id = 0 ){
  73. // Valid id
  74. if( empty( $id ) ) return false;
  75. if( !is_numeric( $id ) ) return false;
  76. // Return Old Video
  77. $sql = 'SELECT `name`';
  78. $sql .= 'FROM `videos`';
  79. $sql .= 'WHERE `id`=\''.strip_tags( $id ).'\' LIMIT 1;';
  80. $res = mysql_query( $sql, $this->conection->con() );
  81. if( $reg = mysql_fetch_assoc( $res ) )
  82. $this->data[] = $reg;
  83. else
  84. return false;
  85. $this->video = $this->directory . $this->data[0]['name'];
  86. if( is_file( $this->video ) )
  87. unlink( $this->video );
  88. // Valid video format and setting codecs
  89. if ( $_FILES['video']['type'] != "video/avi"
  90. and $_FILES['video']['type'] != "video/mp4"
  91. and $_FILES['video']['type'] != "video/webm"
  92. and $_FILES['video']['type'] != "video/x-ms-wmv"
  93. and $_FILES['video']['type'] != "video/x-msvideo"
  94. and $_FILES['video']['type'] != "video/mpeg"
  95. and $_FILES['video']['type'] != "video/quicktime"
  96. and $_FILES['video']['type'] != "video/x-msvideo"
  97. and $_FILES['video']['type'] != "video/x-flv"
  98. and $_FILES['video']['type'] != "application/octet-stream"
  99. and $_FILES['video']['type'] != "application/x-shockwave-flash" )return false;
  100. // Upload file
  101. $file = explode( '.', $_FILES['video']['name'] );
  102. $name = strtolower( $file[0] );
  103. $name = str_replace( '/', '-', $name );
  104. $name = str_replace( ' ', '-', $name );
  105. move_uploaded_file( $_FILES['video']['tmp_name'], $this->directory . $name.'.'.$file[1] );
  106. $sql = 'UPDATE `videos` SET `name`=\''.strip_tags( $name.'.'.$file[1] ).'\'';
  107. $sql .= 'WHERE `id`=\''.strip_tags( $id ).'\';';
  108. $res = mysql_query( $sql, $this->conection->con() );
  109. $this->video = null;
  110. $this->video = strip_tags( 'files/' . $name.'.'.$file[1] );
  111. if( !empty( $res ) )
  112. return true;
  113. else
  114. return false;
  115. }
  116. // Delete Video
  117. public function delete( $id = 0 ){
  118. // Valid id
  119. if( empty( $id ) ) return false;
  120. if( !is_numeric( $id ) ) return false;
  121. // Return Old Image
  122. $sql = 'SELECT `name`';
  123. $sql .= 'FROM `videos`';
  124. $sql .= 'WHERE `id`=\''.strip_tags( $id ).'\';';
  125. $res = mysql_query( $sql, $this->conection->con() );
  126. if( $reg = mysql_fetch_assoc( $res ) )
  127. $this->data[] = $reg;
  128. else
  129. return false;
  130. $this->video = null;
  131. $this->video = $this->directory . $this->data[0]['name'];
  132. if( is_file( $this->video ) )
  133. unlink( $this->video );
  134. $sql = 'DELETE FROM `videos`';
  135. $sql .= 'WHERE `id`=\''.strip_tags( $id ).'\';';
  136. $res = mysql_query( $sql, $this->conection->con() );
  137. if( !empty( $res ) )
  138. return true;
  139. else
  140. return false;
  141. }
  142. // Videos
  143. public function all(){
  144. $sql = 'SELECT `id`, `name`';
  145. $sql .= 'FROM `videos`';
  146. $res = mysql_query( $sql, $this->conection->con() );
  147. if( !empty( $res ) ){
  148. while( $reg = mysql_fetch_assoc( $res ) ){
  149. $this->data[] = $reg;
  150. }
  151. return $this->data;
  152. }else{
  153. return false;
  154. }
  155. }
  156. }
  157. ?>