csv - PHP rename() duplicates file instead of using new version -


our site has .csv file sent on everyday user import data different system. import works correctly sometimes, i'm running problem script importing repeat data instead of using new file.

the system continue import old file until login through sftp view file, grab new file. seems script loading old file memory not clearing out.

for example:

  • a file uploaded on january 1st
  • that file imported correctly.
  • on jan 2nd same file imported again.
  • on jan 3rd same file imported again.
  • on jan 4th view file through sftp.
  • on jan 4th new file imported.

the system continue import old version of file until login through sftp.

my code import below. here explain might happening?

function energyuportal_cron () {      if (($handle = fopen($cfg->dirroot.'/'."report.csv", "r")) !== false) {          while (($data = fgetcsv($handle, 0, ",")) !== false) {             if (energyuportal_check_data($data[1], $data[4])) {             // imports data                     energyuportal_manage_completions($data[1], $data[4], $data[5], $data[7]);             }          }         fclose($handle);          rename($cfg->dirroot.'/'.$cfg->energyuportal_filelocation.'/'."report.csv",                  $cfg->dirroot.'/'.'/old/'."report".date("y-m-d-h-ia").".csv");       } else {         // error     }  return true; } 

log result of stat() on file before doing fopen(). try adding clearstatcache().

if doing include() @ caching settings of byte code compiler, not. therefore start question hosting environment , fs layer.

http://php.net/stat

http://php.net/manual/en/function.clearstatcache.php


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -