0

I use a powershell script (based on this) to monitor a folder and knowing when a file is created.

My script is the following:

### SET FOLDER TO WATCH + FILES TO WATCH + SUBFOLDERS YES/NO
    $watcher = New-Object System.IO.FileSystemWatcher
    $watcher.Path = "H:\draw\"
    $watcher.Filter = "*.nrrd"
    $watcher.IncludeSubdirectories = $true
    $watcher.EnableRaisingEvents = $true  

### DEFINE ACTIONS AFTER AN EVENT IS DETECTED
    $action = 
    { 
        $path = $Event.SourceEventArgs.FullPath
        $changeType = $Event.SourceEventArgs.ChangeType

        if ($path -like '*\tumor\*') 
        {
            Write-Host "The file '$path' was $changeType at '$(Get-Date)'" -fore green 
        }    
    }    
### DECIDE WHICH EVENTS SHOULD BE WATCHED 
    Register-ObjectEvent $watcher "Created" -Action $action
    while ($true) {sleep 5}

When I create the file "by hand" the action is well triggered (the green sentence is displayed).

But the file is not created by hand but by a PHP script. And when the file is created by the PHP script, the action is not triggered.

But when I copy/past the file created by the PHP script, it's triggered, so it's not an issue with the file.

Is it possible to make it work with the creation under PHP?


NB: The file is created this way

$file = fopen($path, 'wb');
fwrite($file, $my_data);
fclose($file);

UPDATE

After further researches, I find out that the issue is not with PHP but when another user/session (that the one who launched the powershell script) is creating the file.

See my other post on SO

3
  • Yes it is. Is it a problem?
    – Atnaize
    Jan 2, 2018 at 13:51
  • @LievenKeersmaekers I think your URL is not appliable anymore because Microsoft has confirmed that this is a problem in IIS 4.0 and 5.0. This problem was first corrected in Windows 2000 Service Pack 3. and the answer on SO is 10 years old ... I think the problem is not the mapped drive itself but when another user/session is creating the file. Because I tried on my local computer and it confirm that.
    – Atnaize
    Jan 3, 2018 at 10:35
  • It's all that came to (old) mind.I'll remove my comments to not clutter the question. Jan 3, 2018 at 17:45

1 Answer 1

0

Seems like PHP is not triggering a create event but possibly a Changed event. Try some of the other events from here

3
  • Have you any source? I tried all the others events and nothing is triggered
    – Atnaize
    Jan 4, 2018 at 7:55
  • No I do not. It was just a thought. There is possibly a property on the file that is not being added by your php script. Have you compared all of the file attributes of your PHP created file and the copied file? Jan 5, 2018 at 3:24
  • The file created by hand (or copy/pasted) has owner DEBIAN\root but the original one have Unix User\www-data
    – Atnaize
    Jan 5, 2018 at 8:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .