RSFile class is a simple file checker for rapidshare servers.
Simple usage:
<?php
require_once("RSFile.php");
// Create some instances using file id and file name.
$rsfiles = RSFile::getInstance($id1, $name1);
/**
* To fully understand the file id and file name lets see a simple example:
* URL: https://rapidshare.com/files/2149820318/RSFile.php
* file id: 2149820318
* file name: RSFile.php
* So from any rapidshare urls we can get this two variables.
*/
// We can create as many instances as we want:
$rsfiles = RSFile::getInstance($id2, $name2);
$rsfiles = RSFile::getInstance($id3, $name3);
// and so on ...
// It is posible to do:
$files = array(
$id4 => $name4,
$id5 => $name5,
$id6 => $name6);
// Use a foreach loop to create all instances
// NOTE* There is a server limitation. You can not check more than 250 - 300
// files in one call. RS server will close the connection.
foreach ($files as $id => $name) {
$rsfiles = RSFile::getInstance($id, $name);
}
// Ok we are done with all files now call processFiles() functions to get
// all files properties from the rapidshare servers:
if ($rsfiles->processFiles() === false) {
// There was an error ... take note or print that ...
echo $rsfiles->errno();
echo $rsfiles->error();
}
// This function can be called only RSFile::MAX_SERVER_CALLS times, by default 3.
// To get the best posible results call this function only once to get all
// files data and not for every new instance.
/*
* Now we have for every file:
* 1. File id: use getFileId() to obtain the file id.
* 2. File name: use getFileName() funtion to get the file name.
* 3. File size: use getFileSize($transform, $precision) function to get file size
* 3.1 $transform can be one of the defined constants SIZE_**
* 3.2 SIZE_B, SIZE_KB, SIZE_MB and SIZE_GB
* 3.3 $precision is used as second parameter in round() function
* 4. File status: use getFileStatus() to obtain it.
* 4.1 We can compare it to any of the 4 constants:
* 4.2 STATUS_FILE_NOT_FOUND, STATUS_FILE_OK, STATUS_SERVER_DOWN and
* STATUS_ILLEGAL_FILE.
* 5. Md5sum: use getMd5sum() to obtain ti.
* 6. Server id: use getServerId() to get it. This is very usefull for
* "creating" the best downlod mirror.
* 7. Short host: use getShortHost() to get it. Like the server id this is
* used for creating the best download mirror.
* 8. Best download mirror: use getDownloadMirror() to get it. You can
* create it using this simple string:
* http://rs{$serverid}{$shorthost}.rapidshare.com/files/{$fileid}/{$filename}
*/
// Ok, now we know most of the functions ...
// If we have only one file then simply use:
if ($rsfile->getFileStatus() === RSFile::STATUS_FILE_OK) {
echo "The file " . $rsfile->getFileName() . " is online!";
echo "File size: " . $rsfile->getFileSize(RSFile::SIZE_MB) . " MB";
echo "File md5sum: " . $rsfile->getMd5sum();
echo "Download mirror: " . $rsfile->getDownloadMirror();
} else if ($rsfile->getFileStatus() === RSFile::STATUS_FILE_NOT_FOUND) {
echo "File was not found!";
} else if ($rsfile->getFileStatus() === RSFile::STATUS_SERVER_DOWN) {
echo "The server is down! Please try again later";
} else if ($rsfile->getFileStatus() === RSFile::STATUS_ILLEGAL_FILE) {
echo "This file was marked as illegal and was deleted from the RS servers!";
}
// If there are more than one file we can use a foreach loop over the instances
foreach ($rsfiles as $rsfile) {
// do things with $rsfile ...
}
// We can get any instance using the $id and the name of the file
// This will return the existing id3.name3 instance. Will create another
// instance if and ONLY if id3.name3 was not created yet.
RSFile::getInstance($id3, $name3)->getFileStatus();
// Last things ...
// You can NOT instantiate using the new keyword
// e.g. $rsfile = new RSFile();
// You can NOT clone this object
// e.g. $new = (clone) $rsfiles;
// You can NOT serialize this object
// e.g. $str = serialize($rsfiles);