Jump to content

downloading only 100 characters of a download.


Recommended Posts

I am writing a script that can determine whether a link is to a file or a html page.  It is a linkchecker script.

 

I want to put in a url and it download and check the url for live or dead status. The only problem is that if a direct file link is put in it downloads the entire file onto my server before checking the contents.  I have almost gotten everything working except for the fact that some of these files are 100mb in size.  I want to limit what my script downloads to check to about the first 50 characters of the file.  It will then use those 50 characters to determine whether or not that file is a html or a direct linked file.  This is what I have so far.

 

<?
$filepath="http://rapidshare.com/files/271981/Ambient_Lounge_6_cd_1_part_1.a.rar";
if ($handle = @fopen($filepath, "r")) {
$content = "";
while (!feof($handle)) {
$part = fread($handle, 50);
$content .= $part;
if (eregi("</body>", $part)) break;
}
fclose($handle);	
if (preg_match("/<!DOCTYPE/i", $content)) 
{
echo "html";
}
else 
{
echo "direct file link";
}
<?

 

 

 

 

I got it.  For future reference this is what I have.

 



<form method=post action=index.php><input type=hidden name=startnow value=go>
Full url (Must include http://):
<input type=text name=link size=60></input>
<br>
<input type=submit value=check>


<?
if (isset($_POST["startnow"])){
$filepath = $_POST["link"];

if (@fclose(@fopen("$filepath", "r"))) {
if ($handle = @fopen($filepath, "r")) {
$content = "";
$part = fread($handle, 50);
$content .= $part;
if (eregi("</body>", $part)) break;
fclose($handle);
} 	
if (preg_match("/<!DOCTYPE/i", $content) || preg_match("/<html>/i", $content)) {
if (preg_match("/rapidshare.com/i", $filepath)) {
if ($handle = @fopen($filepath, "r")) {
$content = "";
while (!feof($handle)) {
$part = fread($handle, 1024);
$content .= $part;
if (eregi("</body>", $part)) break;
}
if (preg_match("/This folder's content has been collected/", $content) || preg_match("/You want to download/", $content) || preg_match("/password-protected folder/", $content)) {
echo "Live Link";

}
ELSE
{
if (preg_match("/This file has been deleted/", $content) || preg_match("/File not found/", $content)){
echo "Dead Link";
}
else 
{
echo "error";
}}}}
Else 
{
Echo "Unsupported Server";
}
}
ELSE
{	
Echo "Direct File Link.(File Exists)"; 
}}
ELSE 
{
echo "File Does Not Exist";
}}

 

This works exactly like what I was wanting to do.  This checks to se if a link is pointing directly to a download file.  If it dos and the file is there it says "Direct File Link.(File Exists). If it does and the file is not there it says "File Does Not Exist".  It it is pointing to a html page it scans that page for certain items to determine if the link is live or dead.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.