I need to create temporary files with PHP for my site. How can I have them numbered in the following manner:
tmp_file_01.jpg
tmp_file_02.jpg
tmp_file_XX.jpg
I’d like to avoid running the shell to figure out what the next available index is.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You’re going to find this is relatively difficult to achieve (note, I’m assuming that you’re trying to avoid filesystem access, in addition to invoking a shell). If you’re married to the idea of incrementing filenames, you’ll probably want to use some sort of shared datastore for holding your sequence number, like mysql, memcached, or APC.
However, depending on what you’re actually trying to do, you may be able to abandon the incrementing numbered scheme, and just use tempnam()
If you’re not against filesystem access, there are lots of options that don’t involve direct shell invocation. e.g., you can just glob(‘tmp_file_*.jpg’)