Updated sample for "/usr/tmp/../../etc/passwd" issue.

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@31988 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Ron Chmara 2000-09-05 01:36:06 +00:00
parent e5755875e4
commit 6653dfa96f

View file

@ -80,10 +80,20 @@ Send this file: <INPUT NAME="userfile" TYPE="file">
<title>Validating file uploads.</title>
<programlisting>
&lt?
$validtmpdir = get_cfg_var("upload_tmp_dir");
/* make sure you're using an uploaded file */
if (strstr ("$validtmpdir", "$userfile") != 0){
copy ("$userfile" "/place/to/put/uploaded/file");
$validtmpdir = get_cfg_var("upload_tmp_dir");
// get the path
$uploaded_path_array = spilt("/","$userfile");
//split the upload name into its components
$inverted_path = array_reverse ($uploaded_path_array);
// reverse the array, so any ending pathname will now be first
$accurate_pathname = "$validtmpdir" . "$inverted_path[0]";
if (file_exists($accurate_pathname )){
//still look for proper temp name
copy ("$accurate_pathname", "/place/to/put/uploaded/file");
} else {
echo "Not an uploaded file!";
exit;