Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with PHP needed (file reading, manipulation)

    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("FILE DELETED <br />");
    }
    } 
    }
    ?>

  • #2
    Regular Coder
    Join Date
    May 2011
    Posts
    242
    Thanks
    1
    Thanked 57 Times in 56 Posts
    Try this
    PHP 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 == || $fStatus == 2;


    $directory "download/"
    $linksfiles glob("" $directory "*.txt"); 
    foreach(
    $linksfiles as $linkfile)
    {
            
    $lf file($linkfile);
            
    $purefilename str_replace($directory"" $linkfile); 
            if (
    $purefilename != "5100c00fdb545e12e8cb4f9c5f69ec21.txt")
            {
                    foreach(
    $lf as $line)
                    {
                            if (
    rs_check($line) === false)
                            {
                                    
    unlink($directory $purefilename);
                                    echo(
    "FILE DELETED <br />");
                                    break;
                            }       
                    }               
            }               
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •