Stack Exchange Network
Stack Exchange network consists of 181 Q&A communities including
Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Visit Stack Exchange
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this community
Anybody can ask a question
The best answers are voted up and rise to the top
10 years, 1 month ago
How can I automatically cleanup failed uploads?
PHP is storing them in
/tmp and all file names look like
phpAbCDeF (basically php followed by 6 characters).
I know that I can use the command:
find /tmp -name php\*
BUT this also removes other temp files that begins with php (created by other processes) that I don't want to delete.
Please suggest a solution.
77.8k 42 42 gold badges 164 164 silver badges 221 221 bronze badges
May 2, 2013 at 15:50
J. Chin J. Chin
111 1 1 silver badge 2 2 bronze badges
It depends on how your files are named. Here are some suggestions:
delete all files whose name is
php followed by exactly 6 characters:
find /tmp -type f -name 'php??????' -delete
Delete all files whose name starts with
php and which are
find /tmp -type f -name "php*" -empty -delete
A better way would be to edit your server's
php-ini file and set the variable
upload_tmp_dir. That way, you can just delete everything in that directory. For example, if you set this in your
You can then simply remove all files from the folder:
May 2, 2013 at 16:50
terdon ♦ terdon
232k 64 64 gold badges 440 440 silver badges 654 654 bronze badges
If this is an application that you wrote/can modify, I would recommend using
register_shutdown_function at the time you create the temporary file. That way you can
unlink even if your script is interrupted.
Apr 13, 2015 at 23:52
2,627 17 17 silver badges 25 25 bronze badges
log in to answer this question.
Not the answer you're looking for? Browse other questions tagged
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our
Accept all cookies
Necessary cookies only