Jump to content

Help with PHP needed (file reading, manipulation)


masky666

Recommended Posts

Hi. I have text files in the directory that contain rapidshare.com links. Now what I need to do is take them one by one and check links inside them one by one using rapidshare API.

 

Everything works fine apart from one thing.

 

It reads files and deletes the ones containing dead links but the problem is that it only deletes the file if ALL links are dead, but not when only one link is dead or some of them.

 

Code:

 

<?php
function rs_check($url){
if (!$url) return false;
$files_pattern= '/\/files\/([^\/]*)\//';
$filename_pattern= '/\/files\/.*\/(.*)/';
preg_match($files_pattern, $url, $matches_id);
preg_match($filename_pattern, $url, $matches_name);
$res= file_get_contents("http://api.rapidshare.com/cgi-bin/rsapi.cgi?sub=checkfiles_v1&files={$matches_id[1]}&filenames={$matches_name[1]}");
list($fId,$fName,$fSize,$fServerId,$fStatus,$fShortHost,$fmd5) =explode(',',$res);
return ($fStatus==1 || $fStatus==2);
}   
$directory = "download/"; 
$linksfiles = glob("" . $directory . "*.txt"); 
foreach($linksfiles as $linkfile)
{
$lf = file_get_contents($linkfile);
$purefilename = str_replace($directory, "" , $linkfile); 
if($purefilename != "5100c00fdb545e12e8cb4f9c5f69ec21.txt"){
if(rs_check($lf) != 1){
unlink($directory . $purefilename);
echo("<br />");
}
} 
}
?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.