Solved

PHP TMP Directory

Posted on 2006-11-25
5
716 Views
Last Modified: 2012-06-21
Hi! I was wondering how temporary files are handled when uploaded in php... Uploaded files are initially stored in the tmp directory - do they get automatically deleted or does it have to be done manually ? Is it done by php, do I have to write a script or is it done by the server periodically, e.g. Cron ?
0
Comment
Question by:Julian Matz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 29

Expert Comment

by:TeRReF
ID: 18012401
You use move_uploaded_file() for this purpose:
http://php.net/manual/en/function.move-uploaded-file.php
0
 
LVL 21

Author Comment

by:Julian Matz
ID: 18012421
Hi TeRReF,

Yes, I know about that function, but I was thinking about files that maybe fail to get moved, etc.
Does that make sense ? Session data gets stored there too, doesn't it ?

Just looked into the server's tmp directory - there's a lot of session data but only very recent... But there are also some files there that are a couple of months old - one of them seems to be an image:

Oct 15 01:45 phpaMbFwY.jpg
0
 
LVL 29

Accepted Solution

by:
TeRReF earned 500 total points
ID: 18012462
Hi Julian,

You're right, by default, session data is stored there as well. Those older files are probably interrupted uploads or something similar.

Usually it's not necessary to clean up your /tmp dir, unless it's on a small partition. Most *NIX systems clean the /tmp dir after a reboot or with a cron job of their own. Also, most tmp files are only a couple of KB's so they won't fill up /tmp that easily.

Since you have files that are a couple of months old, either your server has been up quite a while now or there is no automatic cleaning in place. So, if you do want to remove some PHP specific junk from it, I think a cron job will serve you well.
0
 
LVL 21

Author Comment

by:Julian Matz
ID: 18109526
Thanks!
0
 
LVL 29

Expert Comment

by:TeRReF
ID: 18110456
You're welcome :)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question