init.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. function url_exists( $url = NULL ) {
  3. if( empty( $url ) ){
  4. return FALSE;
  5. }
  6. $ch = curl_init( $url );
  7. // Set a timeout
  8. curl_setopt( $ch, CURLOPT_TIMEOUT, 5 );
  9. curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 5 );
  10. // Set NOBODY to true to make a HEAD-type request
  11. curl_setopt( $ch, CURLOPT_NOBODY, true );
  12. // Allow follow redirects
  13. curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
  14. // Receive the response as string, not output
  15. curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
  16. $data = curl_exec( $ch );
  17. // Get the response code
  18. $httpcode = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
  19. // close connection
  20. curl_close( $ch );
  21. // Accept only answer 200 (Ok), 301 (permanent redirect) or 302 (temporary redirect)
  22. $accepted_response = array( 200, 301, 302 );
  23. if( in_array( $httpcode, $accepted_response ) ) {
  24. return TRUE;
  25. } else {
  26. return FALSE;
  27. }
  28. }
  29. function video_exists( $url ) {
  30. @$headers = get_headers( $url );
  31. $result = FALSE;
  32. if (is_array($headers) || is_object($headers)) {
  33. foreach ( $headers as $hdr ) {
  34. if ( preg_match( '/^HTTP\/\d\.\d\s+(403|404)/', $hdr ) ) {
  35. $result = TRUE; // Found 403 Error
  36. }
  37. }
  38. }
  39. if ( $result === TRUE ) {
  40. return FALSE; // Not exist video
  41. } else {
  42. return TRUE; // Exist video
  43. }
  44. }
  45. function secToDuration( $seconds ) {
  46. $minutes = intval( $seconds/60 );
  47. $seconds = ( $seconds - ( $minutes * 60 ) );
  48. return $minutes . ' minutes ' . $seconds . ' seconds';
  49. }
  50. function bytes( $a ) {
  51. $unim = array("","K","M","G","T","P");
  52. $c = 0;
  53. while ($a>=1000) {
  54. $c++;
  55. $a = $a/1000;
  56. }
  57. return number_format( $a,( $c ? 2 : 0 ),",","." )." ".$unim[$c];
  58. }