function do_upload() { if (!array_key_exists("name", $_REQUEST)) { die("bad form input"); } if (!array_key_exists("file", $_FILES)) { die("bad file input"); } $base_location = BASE_DIR . "/flash"; $url_base = BASE_URL . "/flash"; # move the file to the correct location $origfn = basename($_FILES["file"]["name"]); if (file_exists("{$base_location}/{$origfn}")) { $ext = 0; while (file_exists("{$base_location}/{$origfn}.{$ext}")) { ++$ext; } $fn_out = "{$base_location}/{$origfn}.{$ext}"; $url = "{$url_base}/{$origfn}.{$ext}"; } else { $fn_out = "{$base_location}/{$origfn}"; $url = "{$url_base}/{$origfn}"; } # print a data dump var_dump($_FILES); if (!move_uploaded_file($_FILES["file"]["tmp_name"], $fn_out)) { die("bad file??"); } FlashFile::create_new($_REQUEST["name"], $fn_out, $url); }