1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

[WTH] Multiple file checker

Discussion in 'Programming' started by moker, May 8, 2009.

  1. #1
    Hi,

    I have a txt (text document) file with 300 flv url's. Some are deleted from the server so I need to see which ones do not work.

    The url's looks like this

    And I need a small PHP script to check all those url's if they are working or not, something like http://rapid-hook.com but then for FLV files.

    If you are interested, reply here with price to make this script

    Regards

    moker
     
    moker, May 8, 2009 IP
  2. Demonic

    Demonic Active Member

    Messages:
    821
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #2
    PM Sent with a promising message :).
     
    Demonic, May 8, 2009 IP
  3. papa_face

    papa_face Notable Member

    Messages:
    2,237
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    285
    As Seller:
    100% - 0
    As Buyer:
    0.0% - 0
    #3
    This is to easy to pay for IMO
    Put urls in urls.txt
    <?php
    ini_set('error_reporting', E_ALL);
    $urls = file("urls.txt");
    
    function is_valid_url ( $url )
    {
    		$url = @parse_url($url);
    
    		if ( ! $url) {
    			return false;
    		}
    
    		$url = array_map('trim', $url);
    		$url['port'] = (!isset($url['port'])) ? 80 : (int)$url['port'];
    		$path = (isset($url['path'])) ? $url['path'] : '';
    
    		if ($path == '')
    		{
    			$path = '/';
    		}
    
    		$path .= ( isset ( $url['query'] ) ) ? "?$url[query]" : '';
    
    		if ( isset ( $url['host'] ) AND $url['host'] != gethostbyname ( $url['host'] ) )
    		{
    			if ( PHP_VERSION >= 5 )
    			{
    				$headers = get_headers("$url[scheme]://$url[host]:$url[port]$path");
    			}
    			else
    			{
    				$fp = fsockopen($url['host'], $url['port'], $errno, $errstr, 30);
    
    				if ( ! $fp )
    				{
    					return false;
    				}
    				fputs($fp, "HEAD $path HTTP/1.1\r\nHost: $url[host]\r\n\r\n");
    				$headers = fread ( $fp, 128 );
    				fclose ( $fp );
    			}
    			$headers = ( is_array ( $headers ) ) ? implode ( "\n", $headers ) : $headers;
    			return ( bool ) preg_match ( '#^HTTP/.*\s+[(200|301|302)]+\s#i', $headers );
    		}
    		return false;
    }
    
    foreach($urls as $v)
    	{
    	$valid = is_valid_url($v);
    	if	($valid == "1")
    		{
    		echo $v . " is valid<br />";
    		}
    	else
    		{
    		echo $v . " is NOT valid<br />";
    		}
    	}
    ?>
    Code (markup):
     
    papa_face, May 8, 2009 IP
  4. moker

    moker Peon

    Messages:
    156
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #4
    First of all thanks alot papa_face!

    I have tested your script but it gives "not valid" to every flv file???

    Regards


     
    moker, May 8, 2009 IP
  5. papa_face

    papa_face Notable Member

    Messages:
    2,237
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    285
    As Seller:
    100% - 0
    As Buyer:
    0.0% - 0
    #5
    Damn whitespace lol.
    This should work:
    <?php
    ini_set('error_reporting', E_ALL);
    $urls = file("urls.txt");
    
    function is_valid_url ( $url )
    {
    		$url = @parse_url($url);
    
    		if ( ! $url) {
    			return false;
    		}
    
    		$url = array_map('trim', $url);
    		$url['port'] = (!isset($url['port'])) ? 80 : (int)$url['port'];
    		$path = (isset($url['path'])) ? $url['path'] : '';
    
    		if ($path == '')
    		{
    			$path = '/';
    		}
    
    		$path .= ( isset ( $url['query'] ) ) ? "?$url[query]" : '';
    
    		if ( isset ( $url['host'] ) AND $url['host'] != gethostbyname ( $url['host'] ) )
    		{
    			if ( PHP_VERSION >= 5 )
    			{
    				$headers = get_headers("$url[scheme]://$url[host]:$url[port]$path");
    			}
    			else
    			{
    				$fp = fsockopen($url['host'], $url['port'], $errno, $errstr, 30);
    
    				if ( ! $fp )
    				{
    					return false;
    				}
    				fputs($fp, "HEAD $path HTTP/1.1\r\nHost: $url[host]\r\n\r\n");
    				$headers = fread ( $fp, 128 );
    				fclose ( $fp );
    			}
    			$headers = ( is_array ( $headers ) ) ? implode ( "\n", $headers ) : $headers;
    			return ( bool ) preg_match ( '#^HTTP/.*\s+[(200|301|302)]+\s#i', $headers );
    		}
    		return false;
    }
    
    foreach($urls as $v)
    	{
    	$valid = is_valid_url(trim($v));
    	if	($valid == "1")
    		{
    		echo $v . " is valid<br />";
    		}
    	else
    		{
    		echo $v . " is NOT valid<br />";
    		}
    	}
    ?>
    Code (markup):
    :D
     
    papa_face, May 8, 2009 IP
    moker likes this.
  6. moker

    moker Peon

    Messages:
    156
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #6
    Thanks papa works good!!!!

    REP+

    will hire you soon m8

    thanks again
     
    moker, May 8, 2009 IP