vendredi 19 juin 2015

save document in php if it doesnt exist

Hi I am working on an application to help me with my work, the idea is that it uses phpword to work with several templates that I have, and builds me job folders on onedrive, which is working fairly well. But I have recently modified the following code in my php application, from:

//save Audit Plan 
$folder = "c:/Users/Administrator/OneDrive/Work/Day File/" . $Client .'/'. $ClientSite.'/'.$AuditRef.'/';
if (!file_exists($folder)) { mkdir($folder, 0777, true);};

$AuditPlanFileName = $SiteNamePrefix.$AuditRef." Plan.docx";

$document->save($folder.$AuditPlanFileName);
    unset($template);
}

to:

//save Audit Plan 
$folder = "c:/Users/Administrator/OneDrive/Work/Day File/" . $Client .'/'. $ClientSite.'/'.$AuditRef.'/';
if (!file_exists($folder)) { 
   mkdir($folder, 0777, true);
};

$AuditPlanFileName = $SiteNamePrefix.$AuditRef." Plan.docx";
$targetplan = $SiteNamePrefix.$AuditRef;

if (!file_exists($targetplan)) { $document->save($folder.$AuditPlanFileName);}
   unset($template);
}

The reason for this is to prevent over-righting documents already there, ie if I have got an audit plan prepared by the application, and then start working on it, it would be over-written by the template if i accidentally ran this code.

To me the revised code should only run IF that file doesnt exist, but it runs regardless, even if i have that word file there, the event code replaces it with a fresh one from the template.

I'd appreciate any insights as to why this IF statement isnt doing its job?

Aucun commentaire:

Enregistrer un commentaire