tags:

views:

80

answers:

1

Somehow unlink is not deleting the file. If you see in the file, am copying from $incoming_file_path to $processing_file_path and than after copying is done. I am trying to delete the file in $incoming_file_path but somehow is it not deleting and I really wonder why it is happening so. Kindly advice.

<?php
ini_set('error_reporting',0);
$file = fopen("pid.txt","w+") or die('!fopen');
flock($file, LOCK_EX);

//Folder where xml files will be coming in from UPC
$incoming_file_path = "/home/xmlcontainer";
$processing_file_path = "/home/process_file";
$threshold = time() - 30;
foreach( glob($incoming_file_path.'/*')as $key => $value ) {
  if ( filemtime($value) <= $threshold ) {
    copy($incoming_file_path.$value,$processing_file_path.$value);
    print_r($incoming_file_path.$value."\n");
    unlink($incoming_file_path.$value);
    print_r($incoming_file_path.$value."\n");
    print_r($processing_file_path.$value."\n");
    }
}
flock($file,LOCK_UN);

?>


+1  A: 

readdir() returns the filename without the path. So, in your script instead of filemtime(/home/xmlcontainer/TestInput.xml) only filemtime(TestInput.xml) is executed.

Also $incoming_files contains a single file name (as string) within your while-loop. The nested foreach($incoming_files as ...)will never work.

btw: why do you format the timestamp via date() and then compare the resulting strings against each other?

$file = fopen("pid.txt","w+") or die('!fopen');
flock($file, LOCK_EX);

//Folder where xml files will be coming in from UPC
$incoming_file_path = "/home/xmlcontainer";
$processing_file_path = "/home/process_file";
$threshold = time() - 30;

foreach( glob($incoming_file_path.'/*') as $source ) {
  if ( filemtime($source) <= $threshold ) {
    // copy / move
    // process
    // unlink
  }
}
flock($file,LOCK_UN);
VolkerK
I want to check last modified time of each file present in xmlcontainer folder and if it is less than current time - 30 secs than I assume that it is fully transferred and than I transfer that file to another folder and rm it from xmlcontainer folder. Then I invoke .php script with that file as input.
Rachel