Jump to content

[SOLVED] need to add an incremented value to a file name


jej1216

Recommended Posts

I have a process in a PHP page that creates a file, and it works fine:

if ("$_REQUEST[severity]" == "Level1-No_Obvious_Harm") {
     $sevvar = "1";
} elseif ("$_REQUEST[severity]" == "Level2-Non-permanent_Harm") {
     $sevvar = "2";
} elseif ("$_REQUEST[severity]" == "Level3-Semi-permanent_Harm") {
     $sevvar = "3";
} elseif ("$_REQUEST[severity]" == "Level4-Major_Permanent_Harm") {
     $sevvar = "4";
} elseif ("$_REQUEST[severity]" == "Level5-Death") {
     $sevvar = "5";
} else {
     $sevvar = "Nada";
}

  $file = "notify/$sevvar".".$_REQUEST[fac_id]".".txt";
  $handle = fopen($file, 'w');
  fclose($handle);

 

The name is based on a severity level data value and hospital name.

 

I now need to increment the filename since it is possible to need more than one file with the same severity level and hospital.

 

I see where autoincrementing a database field is covered in PHP, but what about autoincrementing a filename that is created by PHP?

 

TIA,

 

jej1216

 

 

<?php
if ("$_REQUEST[severity]" == "Level1-No_Obvious_Harm") {
     $sevvar = "1";
} elseif ("$_REQUEST[severity]" == "Level2-Non-permanent_Harm") {
     $sevvar = "2";
} elseif ("$_REQUEST[severity]" == "Level3-Semi-permanent_Harm") {
     $sevvar = "3";
} elseif ("$_REQUEST[severity]" == "Level4-Major_Permanent_Harm") {
     $sevvar = "4";
} elseif ("$_REQUEST[severity]" == "Level5-Death") {
     $sevvar = "5";
} else {
     $sevvar = "Nada";
}
  $timestamp = date("U");
  $file = "notify/$sevvar.$_REQUEST[fac_id].$timestamp.txt";
  $handle = fopen($file, 'w');
  fclose($handle);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.