jej1216 Posted September 24, 2008 Share Posted September 24, 2008 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 Link to comment https://forums.phpfreaks.com/topic/125670-solved-need-to-add-an-incremented-value-to-a-file-name/ Share on other sites More sharing options...
jonsjava Posted September 24, 2008 Share Posted September 24, 2008 <?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); Link to comment https://forums.phpfreaks.com/topic/125670-solved-need-to-add-an-incremented-value-to-a-file-name/#findComment-649760 Share on other sites More sharing options...
jej1216 Posted September 24, 2008 Author Share Posted September 24, 2008 Perfect! Thanks! Link to comment https://forums.phpfreaks.com/topic/125670-solved-need-to-add-an-incremented-value-to-a-file-name/#findComment-649888 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.