headers in loop

0 views
Skip to first unread message

Tarun... 【ツ】 Learning is not compulsory. Neither is survival.

unread,
Mar 14, 2009, 5:55:44 AM3/14/09
to php...@googlegroups.com
Hello All

Im struck while making a grabber script ... i want to grab songs from a site so i have made a script to fetch the songs path store them in database ..

and then download them using those paths ..

But my script stops after downloading a single song ...

Below is my code ... Please Help ..

require_once("config.php"); // my database connection file
    $sql_cat_sng="Select * from categories";
    $query_cat_sng=mysql_query($sql_cat_sng);
while ($result_cat_sng=mysql_fetch_array($query_cat_sng)){
    $sql_alb_sng="Select * from albums where catid='".$result_cat_sng[id]."'";
    $query_alb_sng=mysql_query($sql_alb_sng);
    while ($result_alb_sng=mysql_fetch_array($query_alb_sng)) {
        $sql_cnt_songs="Select * from songs where catid='2' and albumid='1'";
        $query_cnt_songs=mysql_query($sql_cnt_songs);
        $row_cnt_songs=mysql_num_rows($query_cnt_songs);
        $songs_cnt=1;
        while ($songs_cnt<=$row_cnt_songs){
            $sql_songs="select * from songs where catid='2' and albumid='1' and status='0'";
            $query_songs=mysql_query($sql_songs);
            while ($result_songs=mysql_fetch_array($query_songs)){             
                $filename =$result_songs[song_path];
                 header("Location: $filename");
                 $sql_update_sng_sts="UPDATE `songs` SET `status` = '1' WHERE `id` =$result_songs[id] ";
                 $query_update_sng_sts=mysql_query($sql_update_sng_sts);
            }
            $songs_cnt++;
        }
        $dir = "C:\Documents and Settings\admin\Desktop\songss";
        $dh = opendir($dir);
        while (($file = readdir($dh)) !== false) {
            //echo "<A HREF=\"$file\">$file</A><BR>\n";
            if (($file!=".") || ($file!="..")){
                $new_file=$file;
                $old_dest="C:/Documents and Settings/admin/Desktop/songss/$file";

                $cat_name=$result_cat_sng['name'];
                $album_name=$result_alb_sng['album'];
                $path=$cat_name."/".$album_name;
                mkdir($path,777);

                $new_dest="C:/Documents and Settings/admin/Desktop/$path/$new_file";
                copy($old_dest,$new_dest);
                unlink($old_dest);
            }
        }
        closedir($dh);
    }
}



Please Help ...
Warm Regards
tarun...@gmail.com
(Tarun Aggarwal)

Amit Kumar Singh

unread,
Mar 14, 2009, 6:52:11 AM3/14/09
to php...@googlegroups.com
Is your script timing out? default is usually 30 seconds.
--
Do Something.Prioritize & Focus.
Learn Something New Every Day ==> http://phpcamp.net

Have you checked out my blog today?.... No, do it now  http://www.amiworks.co.in/talk

Want more?
Join PHPCamp google group http://groups.google.co.in/group/phpcamp

Join Joomla User Group Pune http://groups.google.co.in/group/jugpune
Reply all
Reply to author
Forward
0 new messages