russelburgraymond Posted May 28, 2007 Share Posted May 28, 2007 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"; } <? Quote Link to comment https://forums.phpfreaks.com/topic/53247-downloading-only-100-characters-of-a-download/ Share on other sites More sharing options...
AndyB Posted May 29, 2007 Share Posted May 29, 2007 And does what you have work? In which case what's the question? If not, http://ca.php.net/manual/en/function.file-get-contents.php allows you to specify how many bytes are returned. Quote Link to comment https://forums.phpfreaks.com/topic/53247-downloading-only-100-characters-of-a-download/#findComment-263631 Share on other sites More sharing options...
russelburgraymond Posted May 29, 2007 Author Share Posted May 29, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/53247-downloading-only-100-characters-of-a-download/#findComment-263634 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.