Location: PHPKode > scripts > File Host Link Tester > help.html







<li><a href="#1">How do you use tester.php?</a></li>
<li><a href="#2">How do you interface with class.linktest.php?</a></li>
<li><a href="#3">How do you customize class.linktest.php?</a></li>

<a name="1"></a>
<h3>How do you use tester.php?</h3>

<p>Place each file-host link that you want to check on a new line. There is a list of hosts in the linktest class that are supported. The default is rapidshare.com, rapidshare.de, megaupload.com, megarotic.com, depositfiles.com, and megashares.com (there are many more hosts that it works with though). Use the full url (including http) or it will return as invalid.</p>

<p>Before submitting the links, look at the options below the text area. The default results format is MB, although KB and GB are also available. The rounding input is defaulted to 2 decimals but can be any number (0-9) or left blank for no rounding. If the supported hosts dropdown is true, only links from supported hosts will be processed. If it is false, all links will be processed with no guaranteed results.</p>

<p>Once you click submit, the button text will turn to "processing" but will not be disabled. This is so you can resubmit before the results are printed without having to reload. Be aware that it may take up to several minutes to process (depending on the number of links you entered), because it has to go through several steps of regex and getting html for each link.</p>

<p>Once the links are processed, the valid links will be placed back in the text area and the invalid ones removed. Why? So you can quickly copy the valid ones. To make it even easier, you can press the copy button, which uses javascript and a small flash file (because it's cross-browser supported), to quickly place the contents of the text area into the clipboard.</p>

<p>Finally, the results will be displayed below the text area. The format is an HTML link followed by a message for each link submitted. There are four possible messages. The way a link is validated is if a file size is found using regex. So if a size is returned, then it is valid. Three error messages are possible: "The link provided is not a valid url", "The domain example.com is not a supported host", or "This link for supportedhost.com is invalid."</p>

<a name="2"></a>
<h3>How do you interface with class.linktest.php?</h3>

<p>Below is the simplest possible script for interfacing with the linktest class. I'll explain what needs to go into it and what will be returned.</p>

require_once 'class.linktest.php';
$linktest = new linktest();
$result = $linktest->test($link, $format, $supported);

<p>First of all the variables. The only required variable passed into the test method is the link. The other two (format and supported) have default values and a validation test. The only excepted values for format are KB, MB, or GB. The default is MB. The only excepted values for supported are true and false. The default is true. Rounding is done after the results are passed back from the class.</p>

<p>Now for what is returned. The result variable is an array. If it is a valid link, there will only be one element at index zero with the file size. If it is invalid, there will be three elements as shown below:

$result[0] = false;
$result[1] = 'invalid url';
$result[2] = "The link provided is not a valid url";

<p>The easiest way to test this is to see if the zero index is false or not. All error messages will return false for the first element but will have different error messages and descriptions. See the result test below:</p>

if (!$result[0]) {
    $error = $result[1];
    $description = $result[2];
} else {
    $size = $result[0]

<a name="3"></a>
<h3>How do you customize class.linktest.php?</h3>

<p>It is inevitable that the time will come when the class needs to be modified. Hosts will change their HTML, some will fall out of favor, and other new hosts will arrive on the scene. Customization is easy but you need to know where to look. Let's start with the hosts array. Some examples are below:</p>

$hosts['rapidshare']['rapidshare.com'] 	= array("@rapidshare\hide@address.com", 'curl', 1000/self::CONVERSION, array('@<u>100 MB</u>@i'));
$hosts['rapidshare']['rapidshare.de'] 	= array("@rapidshare\hide@address.com", 'curl', 1, array('@>300 MB<@i'));
$hosts['other']['megaupload.com'] 	= array("@megaupload\hide@address.com", 'curl', 1);
$hosts['other']['megarotic.com'] 	= array("@megarotic\hide@address.com", 'curl', 1);
$hosts['other']['depositfiles.com'] 	= array("@depositfiles\hide@address.com", 'file', 1);
$hosts['other']['megashares.com'] 	= array("@megashares\hide@address.com", 'curl', 1, array('@ hide@address.com'));

<p>The first key of the array is used to identify the method that should be called. Rapidshare requires a two step process to validate so it has its own method. If you need to add a host that requires more than one step, make a method for it and use the key to call it, and use the rapidshare method as a template. The second key is simply the domain name of the host.</p>

<p>Following that is an array of values specific to that domain. First is the pattern for matching the host domain against the domain name that was extracted from the url. Notice the slash (or escape character) in front of the period. It is important to put that in or it will cause a fatal error. Next, is the method for getting the HTML. Curl is the default but sometimes doesn't work, so file is an available alternative. Next is the adjustment variable, which is used if the host doesn't calculate the file size properly, like rapidshare.com. The default is 1.</p>

<p>Finally, is an embedded array, which is optional. It is the filters array. Some hosts have text on the file page or the error page that prevents the proper results from returning. The filter is a regex pattern that is used to remove the text that is messing up the results.</p>

<p>Other than the hosts array or making a new method, nothing should have to be changed in the class. I don't claim to be a regex expert so you may want to change the regex patterns, however, they have been tested and are working. The main pattern for finding the file size is a constant at the top of the class:</p>

const PATTERN = "@([\d\.,\s]+)(KB|MB|GB)@i";

<p>It returns both the file size and the size format. Changing it may result in having to change the code that uses the results. The other regex patterns that are used are embedded in the code and need to be found in their context in order to be changed. It is unlikely that you'll have to change them. However, the most likely pattern you'll have to change is in the rapidshare method.</p>

<p>Contact me for any further assistance needed or to make any change requests: <a href="mailto:hide@address.com">hide@address.com</a></p>

<h5>Copyright © 2008, Max Power</h5>


Return current item: File Host Link Tester