简体   繁体   中英

Php Script to delete and create files and folder using .bat not working when run using Windows Scheduler

I was trying create folder and save images using php in loop, it is running fine from .bat file manually.

It is creating all respective folders and image files, but when run using windows scheduler its is not creating folders.

The job is successfully completed when checked the Scheduler status.

Also I ran a delete to clean up old folders and images this also works fine if I ran the .bat file manually but not deleting any folder when run through scheduler.

The below is the .bat file code.

Am I missing some permission issue in Scheduler that prevent me from creating folder and images?

c:\xampp\php\php.exe -f c:\xampp\htdocs\retrieve_image.php

This is the bat file code I have created to run the *.php file

while ($row = $db->fetch_array($r2)) {

        $sysid = $row[ml_num];
        $prop_id = $row[property_id];


        $n = 1;
        $dir = 'photos/' . $sysid;
        if (!is_dir($dir)) mkdir($dir); 

        $photos = $rets->GetObject('Property', 'Photo', $sysid);            
        foreach ($photos as $photo) {
            $loc = $dir . "/" . $n . ".jpg";
            file_put_contents($dir . '/' . $n . '.jpg', $photo['Data']);

            if (imagecreatefromjpeg($loc) !== false) {
                echo $loc . "<br/>";
                $sql2 = "INSERT INTO property_images(property_id, pimg_name,status) values('$prop_id','$loc',1)";

                $r3 = $db->query($sql2);
            }
            else
            {
                $status = unlink($loc);
            }
            $n++;

        }

        $i++;
    }

This is the php code to retrieve image and create a new folder and put images in while loop. It is working fine when I ran .bat file manually.

Please help me in running this action through windows scheduler.

Go the task properties --> Action tab --> Edit --> Fill up as below:

Start in (optional): Put the full path to your batch script location

eg: C:\\xampp\\htdocs\\

Then Click OK

It works for me. Good Luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM