<?php
$file_field = "fileatt";
if (!isset($_FILES[$file_field])) {
echo "file's field is not set.";
exit();
}
if ($_FILES[$file_field]["error"] != 0) {
echo "upload error.";
exit();
}
if ($_FILES[$file_field]["name"] == "") {
echo "name is empty.";
exit();
}
$file_basename = basename($_FILES[$file_field]["name"]);
if ($file_basename != "") {
echo "file basename is empty.";
exit();
}
$time = time();
while (file_exists("/tmp/{$time}")) {
$time++;
}
if (!mkdir("/tmp/{$time}")) {
echo "mkdir failed.";
exit();
}
$file_path = "/tmp/{$time}/{$file_basename}";
if (!@move_uploaded_file($_FILES[$file_field]['tmp_name'], $file_path) {
echo "move_uploaded_file failed.";
exit();
}
// use $file_path for the mailer
// After the mailer, remove the file and the path:
unlink($file_path);
rmdir("/tmp/{$time}");
?>
|