$action = $_GET['action'];
require_once('auc.main.class.inc.php');
$auc = new auc();
if ($action == 'uploadfile') {
$auc = new auc();
$result = $auc->upload("file");
if (is_array($result)) {
echo 'Something Went Wrong';
echo '
';<br> var_dump($result);<br> echo '';
ç±»æ件
class auc {
public $errors = array(); //array used to store any errors that occur.
public $upload_dir = ''; //the upload_dir being used by the script
public $make_safe = false; //default don't modify the file name to safe version
public $max_file_size = 1048576; //Max File Size in Bytes, 1MB
public $overwrite = false; //default don't overwrite files that already exsist
public $check_file_type = false; //don't check for file type by default but can check for allowed and denied files.
public $allowed_mime_types = array('image/jpeg', 'image/png', 'image/gif', 'image/tiff'); //array of allowed mime types used when check_file_type is set to allowed
public $denied_mime_types = array('application/x-php', 'text/html'); //array of denied mime types used when check_file_type is set to denied
/**
* Check if the upload dir is valid, if it is not valid attempt to make the dir, if dir is succesfully created chmod it to 0777.
* If any elments fail return false else set upload_dir and return true.
* @param string $dir
* @param boolean $mkdir
* @return true or false
*/
public function upload_dir($dir, $mkdir = false) {
$errors =& $this->errors;
$status = true;
if (!is_dir($dir)) {
if ($mkdir) {
if (!mkdir($dir)) {
$status = false;
} else {
if (!chmod($dir, 0777)) $status = false;
}
} else {
$status = false;
}
}
if ($status) {
$this->upload_dir = $dir;
return true;
} else {
$errors['general'][] = 'Upload Dir is Not Valid and/or a dir could not be created/chmod.';
return false;
}
}
/**
* check that the upload dir is valid and that it is writeable
*
* @param string $dir
* @return true or false
*/
public function check_dir($dir) {
if (!is_dir($dir) || !is_writable($dir)) return false;
return true;
}
/**
* make the uploaded file name safe
*
* @param string $file_name
* @return safe file name
*/
public function make_safe($file_name) {
return str_replace(' ', '_', $file_name);
}
/**
* Check the Attemted Uploads for errors etc if everything goes good move the file, to the upload_dir.
*
* @param array $object
* @return unknown
*/
public function upload($object) {
$errors =& $this->errors;
if (empty($errors['general'])) {
if (empty($this->upload_dir)) $this->upload_dir = dirname(__FILE__).'/'; //if no default upload_dir has been specified used the current dir.
if ($this->check_dir($this->upload_dir)) {
$files = $_FILES[$object];
$count = count($files['name']) - 1;
echo '
';<br> var_dump($files);<br> echo '';
/**
* Handle the Exceptions trigered by errors within upload code.
*
*/
class TrigerErrorException extends Exception {
protected $file = "";
public function __construct($message, $file = "", $code = 0) {
$this->file = $file;
parent::__construct($message, $code);
}
public function Message() {
return "{$this->message}";
}
}
?>