奇怪的行为:在php中取消链接而不删除文件

奇怪的行为:在php中取消链接而不删除文件,php,Php,不知何故,取消链接并不是在删除文件。如果您在文件中看到,我将从$incoming_file_path复制到$processing_file_path,然后在复制完成后进行复制。我试图删除$incoming_file_路径中的文件,但不知何故它没有删除,我真的很想知道为什么会这样。好心的建议 <?php ini_set('error_reporting',0); $file = fopen("pid.txt","w+") or die('!fopen'); flock($file, LOCK

不知何故,取消链接并不是在删除文件。如果您在文件中看到,我将从$incoming_file_path复制到$processing_file_path,然后在复制完成后进行复制。我试图删除$incoming_file_路径中的文件,但不知何故它没有删除,我真的很想知道为什么会这样。好心的建议

<?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);

?>


readdir()返回不带路径的文件名。因此,在脚本中,只执行
filemtime(TestInput.xml)
而不是
filemtime(/home/xmlcontainer/TestInput.xml)

另外,$incoming_files在while循环中包含一个文件名(作为字符串)。嵌套的
foreach($incoming_files as…)
将永远无法工作

顺便问一下:为什么要通过date()格式化时间戳,然后将结果字符串相互比较

$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);
$file=fopen(“pid.txt”,“w+”)或die(“!fopen”);
flock($file,LOCK_EX);
//从UPC传入xml文件的文件夹
$incoming_file_path=“/home/xmlcontainer”;
$processing_file_path=“/home/process_file”;
$threshold=time()-30;
foreach(glob($incoming_file_path./*')作为$source){
if(filemtime($source)readdir()返回的文件名没有路径。因此,在脚本中,而不是
filemtime(/home/xmlcontainer/TestInput.xml)
只执行
filemtime(TestInput.xml)

另外,$incoming_files在while循环中包含一个文件名(作为字符串)。嵌套的
foreach($incoming_files as…)
将永远无法工作

顺便问一下:为什么要通过date()格式化时间戳,然后将结果字符串相互比较

$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);
$file=fopen(“pid.txt”,“w+”)或die(“!fopen”);
flock($file,LOCK_EX);
//从UPC传入xml文件的文件夹
$incoming_file_path=“/home/xmlcontainer”;
$processing_file_path=“/home/process_file”;
$threshold=time()-30;
foreach(glob($incoming_file_path./*')作为$source){

如果(filemtime($source)我在
$incoming\u files\u LM=date(“F d Y H:I:s.”,filemtime($incoming\u files”))处收到
错误
意外的T\u字符串
。“\n”;
,不知道为什么会出现这样的错误。我检查了常见原因,但没有发现任何错误。非常感谢您的指导。上次我查看时,变量名称中不能包含空格($incoming_files _LM=…),我已更正了该错误,但现在收到多个警告,如
filemtime():TestInput.xml的stat失败,
为foreach()提供的参数无效
但代码没有正常运行。TestInput.xml是xmlcontainer文件夹中存在的xml文件之一。
$incoming\u files
不是数组,因此它不能与
foreach
一起使用-请参阅
readdir
上的文档:我在
incoming\u files\L上收到
错误
作为
意外的t\u字符串
M=date(“F d Y H:i:s.”,filemtime($incoming_files”)。“\n”
,不确定它为什么会给我这样一个错误。我检查了常见原因,但没有找到任何错误。非常感谢您的指导。上次我查看时,变量名称中不能包含空格($incoming_files _LM=…)我已经纠正了这个错误,但是现在收到了多个警告,比如TestInput.xml的stat失败和foreach()提供的参数无效
但代码没有正常运行。TestInput.xml是xmlcontainer文件夹中存在的xml文件之一。
$incoming_files
不是数组,因此不能与
foreach
一起使用-请参阅
readdir
上的文档:我想检查xmlcontainer文件夹中每个文件的上次修改时间,以及它是否为less比当前时间-比我假设的完全传输时间短30秒,然后我将该文件传输到另一个文件夹,并从xmlcontainer文件夹对其进行rm。然后,我调用该文件作为输入的.php脚本。我想检查xmlcontainer文件夹中每个文件的上次修改时间,如果它比我假设的时间短30秒它被完全传输,然后我将该文件传输到另一个文件夹,并将其从xmlcontainer文件夹中rm出来。然后我使用该文件作为输入调用.php脚本。