Hi I would like a crhon job to do the following:

1) copy a zip file, eg: www.somesite.com/file.zip to www.mysite.com/file.zip
2) unzip such file
3) move the unziped files to another directory, after reading one of those files.

Please, I have no idea on how to do this... (my thing is C#.net)

Thanks for your sugestions :)

Recommended Answers

All 4 Replies

Member Avatar for diafol

Have you searched Google or the php manual? This is a php forum to help with your code. Show your code so far.

ah don't worry guys, I figured it out, a few hours later the past week xD

in a small brief, this is what I did.

1) lots of JSON parsing and data extraction

Then I downloaded the zip file to my server like:

set_time_limit(0);
    copy($url, 'file.zip');

after that, unziped the file

$zip = new ZipArchive;
    if ($zip->open('game.zip') === TRUE) {
        $zip->extractTo('./');
        $zip->close();
        echo 'unzip ok <br/>';
    } else {
        echo 'unzip failed';
    }

//here more JSON parsing, and fun stuff

and finally copied the original to a new directory, and deleted the one in my "chron_job_folder", using the 2 following methods:

//copy the directory recursively
function full_copy($source, $target) {
    if (is_dir($source)) {
        @mkdir($target);
        $d = dir($source);
        while (FALSE !== ( $entry = $d->read() )) {
            if ($entry == '.' || $entry == '..') {
                continue;
            }
            $Entry = $source . '/' . $entry;
            if (is_dir($Entry)) {
                full_copy($Entry, $target . '/' . $entry);
                continue;
            }
            copy($Entry, $target . '/' . $entry);
        }

        $d->close();
    } else {
        copy($source, $target);
    }
}

//reomove the directory recursively
function rrmdir($dir) {
   if (is_dir($dir)) {
     $objects = scandir($dir);
     foreach ($objects as $object) {
       if ($object != "." && $object != "..") {
         if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object);
       }
     }
     reset($objects);
     rmdir($dir);
   }
 }

and, the responses to my post from ppl trying to help = 0 (again)

I guess this days, everybody is so busy. but I leave the complete solution to 3 common troubles here :) because I like to share knowledge, As my university slogan said: "Go and teach everybody".

I hope someone finds this post usefull :)

oh and of course... to set the cron job, simply go to your cPanel and add new cron job
there are a few nice features to make this easy, but basically you type in:

path_to_php -q full_path_to_your_php_script

and voila, you got it :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.