Note to self: how to find the upload directory in PHP
Published November 1st, 2006Here’s one of those things that’s bugged me for a while, and I’ve just found the answer: how to get the location of the directory that uploaded files are stored in by PHP. Turns out it’s simple:
get_cfg_var('upload_tmp_dir');
Duh.
As an aside, if you’re dealing with uploaded files then you should be aware that it’s possible to tamper with the $_FILES array and potentially do malicious things with it. So you should always make use of the is_uploaded_file() and/or move_uploaded_file() functions. This will ensure that any manipulation you do to the file will only ever proceed if it is a file that really has been uploaded by the user.
Leave a comment
Comment Policy: First time comments are moderated. Please be patient.